<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span id="local-6989586621679539889"><span id="local-6989586621679539890"></span></span><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP
           , NoImplicitPrelude
           , BangPatterns
           , MagicHash
           , UnboxedTuples
           , UnliftedFFITypes
           , StandaloneDeriving
           , RankNTypes
  #-}</span><span>
</span><span id="line-11"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Module      :  GHC.Conc.Sync</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2002</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- Portability :  non-portable (GHC extensions)</span><span>
</span><span id="line-22"></span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- Basic concurrency stuff.</span><span>
</span><span id="line-24"></span><span class="hs-comment">--</span><span>
</span><span id="line-25"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span class="hs-comment">-- No: #hide, because bits of this module are exposed by the stm package.</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- However, we don't want this module to be the home location for the</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- bits it exports, we'd rather have Control.Concurrent and the other</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- higher level modules be the home.  Hence:</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-comment">-- #not-home</span><span>
</span><span id="line-33"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Conc.Sync</span><span>
</span><span id="line-34"></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier">ThreadId</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#showThreadId"><span class="hs-identifier">showThreadId</span></a></span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Forking and suchlike</span></span><span>
</span><span id="line-38"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier">forkIO</span></a></span><span>
</span><span id="line-39"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#forkIOWithUnmask"><span class="hs-identifier">forkIOWithUnmask</span></a></span><span>
</span><span id="line-40"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#forkOn"><span class="hs-identifier">forkOn</span></a></span><span>
</span><span id="line-41"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#forkOnWithUnmask"><span class="hs-identifier">forkOnWithUnmask</span></a></span><span>
</span><span id="line-42"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#numCapabilities"><span class="hs-identifier">numCapabilities</span></a></span><span>
</span><span id="line-43"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#getNumCapabilities"><span class="hs-identifier">getNumCapabilities</span></a></span><span>
</span><span id="line-44"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#setNumCapabilities"><span class="hs-identifier">setNumCapabilities</span></a></span><span>
</span><span id="line-45"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#getNumProcessors"><span class="hs-identifier">getNumProcessors</span></a></span><span>
</span><span id="line-46"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#numSparks"><span class="hs-identifier">numSparks</span></a></span><span>
</span><span id="line-47"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier">childHandler</span></a></span><span>
</span><span id="line-48"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier">myThreadId</span></a></span><span>
</span><span id="line-49"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#killThread"><span class="hs-identifier">killThread</span></a></span><span>
</span><span id="line-50"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#throwTo"><span class="hs-identifier">throwTo</span></a></span><span>
</span><span id="line-51"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#par"><span class="hs-identifier">par</span></a></span><span>
</span><span id="line-52"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#pseq"><span class="hs-identifier">pseq</span></a></span><span>
</span><span id="line-53"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#runSparks"><span class="hs-identifier">runSparks</span></a></span><span>
</span><span id="line-54"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#yield"><span class="hs-identifier">yield</span></a></span><span>
</span><span id="line-55"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#labelThread"><span class="hs-identifier">labelThread</span></a></span><span>
</span><span id="line-56"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#mkWeakThreadId"><span class="hs-identifier">mkWeakThreadId</span></a></span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadStatus"><span class="hs-identifier">ThreadStatus</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#BlockReason"><span class="hs-identifier">BlockReason</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#threadStatus"><span class="hs-identifier">threadStatus</span></a></span><span>
</span><span id="line-60"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#threadCapability"><span class="hs-identifier">threadCapability</span></a></span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#newStablePtrPrimMVar"><span class="hs-identifier">newStablePtrPrimMVar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#PrimMVar"><span class="hs-identifier">PrimMVar</span></a></span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Allocation counter and quota</span></span><span>
</span><span id="line-65"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#setAllocationCounter"><span class="hs-identifier">setAllocationCounter</span></a></span><span>
</span><span id="line-66"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#getAllocationCounter"><span class="hs-identifier">getAllocationCounter</span></a></span><span>
</span><span id="line-67"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#enableAllocationLimit"><span class="hs-identifier">enableAllocationLimit</span></a></span><span>
</span><span id="line-68"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#disableAllocationLimit"><span class="hs-identifier">disableAllocationLimit</span></a></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span>        </span><span class="annot"><span class="hs-comment">-- * TVars</span></span><span>
</span><span id="line-71"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier">STM</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier">atomically</span></a></span><span>
</span><span id="line-73"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier">retry</span></a></span><span>
</span><span id="line-74"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#orElse"><span class="hs-identifier">orElse</span></a></span><span>
</span><span id="line-75"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#throwSTM"><span class="hs-identifier">throwSTM</span></a></span><span>
</span><span id="line-76"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#catchSTM"><span class="hs-identifier">catchSTM</span></a></span><span>
</span><span id="line-77"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier">TVar</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-78"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#newTVar"><span class="hs-identifier">newTVar</span></a></span><span>
</span><span id="line-79"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier">newTVarIO</span></a></span><span>
</span><span id="line-80"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#readTVar"><span class="hs-identifier">readTVar</span></a></span><span>
</span><span id="line-81"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#readTVarIO"><span class="hs-identifier">readTVarIO</span></a></span><span>
</span><span id="line-82"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier">writeTVar</span></a></span><span>
</span><span id="line-83"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#unsafeIOToSTM"><span class="hs-identifier">unsafeIOToSTM</span></a></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Miscellaneous</span></span><span>
</span><span id="line-86"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#withMVar"><span class="hs-identifier">withMVar</span></a></span><span>
</span><span id="line-87"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#modifyMVar_"><span class="hs-identifier">modifyMVar_</span></a></span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#setUncaughtExceptionHandler"><span class="hs-identifier">setUncaughtExceptionHandler</span></a></span><span>
</span><span id="line-90"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#getUncaughtExceptionHandler"><span class="hs-identifier">getUncaughtExceptionHandler</span></a></span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#reportError"><span class="hs-identifier">reportError</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#reportStackOverflow"><span class="hs-identifier">reportStackOverflow</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#reportHeapOverflow"><span class="hs-identifier">reportHeapOverflow</span></a></span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier">sharedCAF</span></a></span><span>
</span><span id="line-95"></span><span>        </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-96"></span><span>
</span><span id="line-97"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-98"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Typeable.html"><span class="hs-identifier">Data.Typeable</span></a></span><span>
</span><span id="line-101"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-104"></span><span class="hs-keyword">import</span><span> </span><span class="hs-pragma">{-# SOURCE</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="annot"><a href="GHC.IO.Handle.html"><span class="hs-identifier">GHC.IO.Handle</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.Handle.html#hFlush"><span class="hs-identifier">hFlush</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-105"></span><span class="hs-keyword">import</span><span> </span><span class="hs-pragma">{-# SOURCE</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="annot"><a href="GHC.IO.StdHandles.html"><span class="hs-identifier">GHC.IO.StdHandles</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier">stdout</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-106"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Int.html"><span class="hs-identifier">GHC.Int</span></a></span><span>
</span><span id="line-107"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-108"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.UTF8.html"><span class="hs-identifier">GHC.IO.Encoding.UTF8</span></a></span><span>
</span><span id="line-109"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-110"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>
</span><span id="line-111"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Foreign.html"><span class="hs-identifier">GHC.Foreign</span></a></span><span>
</span><span id="line-112"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>
</span><span id="line-113"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.MVar.html"><span class="hs-identifier">GHC.MVar</span></a></span><span>
</span><span id="line-114"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Ptr.html"><span class="hs-identifier">GHC.Ptr</span></a></span><span>
</span><span id="line-115"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-116"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Show.html#Show"><span class="hs-identifier">Show</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Show.html#showParen"><span class="hs-identifier">showParen</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Show.html#showString"><span class="hs-identifier">showString</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-117"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Stable.html"><span class="hs-identifier">GHC.Stable</span></a></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Stable.html#StablePtr"><span class="hs-identifier">StablePtr</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-118"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Weak.html"><span class="hs-identifier">GHC.Weak</span></a></span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html"><span class="hs-identifier">Unsafe.Coerce</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html#unsafeCoerce%23"><span class="hs-identifier">unsafeCoerce#</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-keyword">infixr</span><span> </span><span class="hs-number">0</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#par"><span class="hs-operator hs-type">`par`</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#pseq"><span class="hs-operator hs-type">`pseq`</span></a></span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-125"></span><span class="hs-comment">-- 'ThreadId', 'par', and 'fork'</span><span>
</span><span id="line-126"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-127"></span><span>
</span><span id="line-128"></span><span class="hs-keyword">data</span><span> </span><span id="ThreadId"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-var">ThreadId</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="ThreadId"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-var">ThreadId</span></a></span></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span>
</span><span id="line-129"></span><span class="hs-comment">-- ToDo: data ThreadId = ThreadId (Weak ThreadId#)</span><span>
</span><span id="line-130"></span><span class="hs-comment">-- But since ThreadId# is unlifted, the Weak type must use open</span><span>
</span><span id="line-131"></span><span class="hs-comment">-- type variables.</span><span>
</span><span id="line-132"></span><span class="hs-comment">{- ^
A 'ThreadId' is an abstract type representing a handle to a thread.
'ThreadId' is an instance of 'Eq', 'Ord' and 'Show', where
the 'Ord' instance implements an arbitrary total ordering over
'ThreadId's. The 'Show' instance lets you convert an arbitrary-valued
'ThreadId' to string form; showing a 'ThreadId' value is occasionally
useful when debugging or diagnosing the behaviour of a concurrent
program.

/Note/: in GHC, if you have a 'ThreadId', you essentially have
a pointer to the thread itself.  This means the thread itself can\'t be
garbage collected until you drop the 'ThreadId'.
This misfeature will hopefully be corrected at a later date.

-}</span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">-- | @since 4.2.0.0</span><span>
</span><span id="line-149"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539789"><span id="local-6989586621679539791"><span class="annot"><a href="GHC.Show.html#Show"><span class="hs-identifier hs-type">Show</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-150"></span><span>   </span><span id="local-6989586621679539783"><span class="annot"><span class="annottext">showsPrec :: Int -&gt; ThreadId -&gt; ShowS
</span><a href="GHC.Show.html#showsPrec"><span class="hs-identifier hs-var hs-var hs-var hs-var">showsPrec</span></a></span></span><span> </span><span id="local-6989586621679539781"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539781"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span id="local-6989586621679539780"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679539780"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; ShowS -&gt; ShowS
</span><a href="GHC.Show.html#showParen"><span class="hs-identifier hs-var">showParen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539781"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">11</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(ShowS -&gt; ShowS) -&gt; ShowS -&gt; ShowS
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-151"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; ShowS
</span><a href="GHC.Show.html#showString"><span class="hs-identifier hs-var">showString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ThreadId &quot;</span></span><span> </span><span class="annot"><span class="annottext">ShowS -&gt; ShowS -&gt; ShowS
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span>
</span><span id="line-152"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; CInt -&gt; ShowS
forall a. Show a =&gt; Int -&gt; a -&gt; ShowS
</span><a href="GHC.Show.html#showsPrec"><span class="hs-identifier hs-var">showsPrec</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539781"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadId# -&gt; CInt
</span><a href="GHC.Conc.Sync.html#getThreadId"><span class="hs-identifier hs-var">getThreadId</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadId -&gt; ThreadId#
</span><a href="GHC.Conc.Sync.html#id2TSO"><span class="hs-identifier hs-var">id2TSO</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679539780"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="annot"><a href="GHC.Conc.Sync.html#showThreadId"><span class="hs-identifier hs-type">showThreadId</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-155"></span><span id="showThreadId"><span class="annot"><span class="annottext">showThreadId :: ThreadId -&gt; String
</span><a href="GHC.Conc.Sync.html#showThreadId"><span class="hs-identifier hs-var hs-var">showThreadId</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span>
</span><span id="line-156"></span><span>
</span><span id="line-157"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;rts_getThreadId&quot;</span></span><span> </span><span id="getThreadId"><span class="annot"><a href="GHC.Conc.Sync.html#getThreadId"><span class="hs-identifier hs-var">getThreadId</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="annot"><a href="GHC.Conc.Sync.html#id2TSO"><span class="hs-identifier hs-type">id2TSO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span>
</span><span id="line-160"></span><span id="id2TSO"><span class="annot"><span class="annottext">id2TSO :: ThreadId -&gt; ThreadId#
</span><a href="GHC.Conc.Sync.html#id2TSO"><span class="hs-identifier hs-var hs-var">id2TSO</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539775"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539775"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539775"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-161"></span><span>
</span><span id="line-162"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;eq_thread&quot;</span></span><span> </span><span id="eq_thread"><span class="annot"><a href="GHC.Conc.Sync.html#eq_thread"><span class="hs-identifier hs-var">eq_thread</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CBool"><span class="hs-identifier hs-type">CBool</span></a></span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;cmp_thread&quot;</span></span><span> </span><span id="cmp_thread"><span class="annot"><a href="GHC.Conc.Sync.html#cmp_thread"><span class="hs-identifier hs-var">cmp_thread</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-165"></span><span class="hs-comment">-- Returns -1, 0, 1</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-comment">-- | @since 4.2.0.0</span><span>
</span><span id="line-168"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539770"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-type">Eq</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-169"></span><span>  </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539764"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539764"><span class="hs-identifier hs-var">t1</span></a></span></span><span> </span><span id="local-6989586621679539763"><span class="annot"><span class="annottext">== :: ThreadId -&gt; ThreadId -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">==</span></a></span></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539762"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539762"><span class="hs-identifier hs-var">t2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; ThreadId# -&gt; CBool
</span><a href="GHC.Conc.Sync.html#eq_thread"><span class="hs-identifier hs-var">eq_thread</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539764"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539762"><span class="hs-identifier hs-var">t2</span></a></span><span> </span><span class="annot"><span class="annottext">CBool -&gt; CBool -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">CBool
</span><span class="hs-number">0</span></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="hs-comment">-- | @since 4.2.0.0</span><span>
</span><span id="line-172"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539746"><span id="local-6989586621679539748"><span id="local-6989586621679539750"><span id="local-6989586621679539752"><span id="local-6989586621679539754"><span id="local-6989586621679539756"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-type">Ord</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span></span></span></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-173"></span><span>  </span><span id="local-6989586621679539737"><span class="annot"><span class="annottext">compare :: ThreadId -&gt; ThreadId -&gt; Ordering
</span><a href="../../ghc-prim/src/GHC.Classes.html#compare"><span class="hs-identifier hs-var hs-var hs-var hs-var">compare</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539735"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539735"><span class="hs-identifier hs-var">t1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539734"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539734"><span class="hs-identifier hs-var">t2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; ThreadId# -&gt; CInt
</span><a href="GHC.Conc.Sync.html#cmp_thread"><span class="hs-identifier hs-var">cmp_thread</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539735"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539734"><span class="hs-identifier hs-var">t2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-174"></span><span>    </span><span class="hs-glyph">-</span><span class="hs-number">1</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#LT"><span class="hs-identifier hs-var">LT</span></a></span><span>
</span><span id="line-175"></span><span>    </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#EQ"><span class="hs-identifier hs-var">EQ</span></a></span><span>
</span><span id="line-176"></span><span>    </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#GT"><span class="hs-identifier hs-var">GT</span></a></span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span class="hs-comment">-- | Every thread has an allocation counter that tracks how much</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- memory has been allocated by the thread.  The counter is</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- initialized to zero, and 'setAllocationCounter' sets the current</span><span>
</span><span id="line-181"></span><span class="hs-comment">-- value.  The allocation counter counts *down*, so in the absence of</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- a call to 'setAllocationCounter' its value is the negation of the</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- number of bytes of memory allocated by the thread.</span><span>
</span><span id="line-184"></span><span class="hs-comment">--</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- There are two things that you can do with this counter:</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- * Use it as a simple profiling mechanism, with</span><span>
</span><span id="line-188"></span><span class="hs-comment">--   'getAllocationCounter'.</span><span>
</span><span id="line-189"></span><span class="hs-comment">--</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- * Use it as a resource limit.  See 'enableAllocationLimit'.</span><span>
</span><span id="line-191"></span><span class="hs-comment">--</span><span>
</span><span id="line-192"></span><span class="hs-comment">-- Allocation accounting is accurate only to about 4Kbytes.</span><span>
</span><span id="line-193"></span><span class="hs-comment">--</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-195"></span><span class="annot"><a href="GHC.Conc.Sync.html#setAllocationCounter"><span class="hs-identifier hs-type">setAllocationCounter</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Int.html#Int64"><span class="hs-identifier hs-type">Int64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-196"></span><span id="setAllocationCounter"><span class="annot"><span class="annottext">setAllocationCounter :: Int64 -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#setAllocationCounter"><span class="hs-identifier hs-var hs-var">setAllocationCounter</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Int.html#I64%23"><span class="hs-identifier hs-type">I64#</span></a></span><span> </span><span id="local-6989586621679539732"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539732"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539731"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539731"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-197"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; State# RealWorld -&gt; State# RealWorld
</span><a href="../../ghc-prim/src/GHC.Prim.html#setThreadAllocationCounter%23"><span class="hs-identifier hs-var">setThreadAllocationCounter#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539732"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539731"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span id="local-6989586621679539730"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539730"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539730"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-198"></span><span>
</span><span id="line-199"></span><span class="hs-comment">-- | Return the current value of the allocation counter for the</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- current thread.</span><span>
</span><span id="line-201"></span><span class="hs-comment">--</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-203"></span><span class="annot"><a href="GHC.Conc.Sync.html#getAllocationCounter"><span class="hs-identifier hs-type">getAllocationCounter</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Int.html#Int64"><span class="hs-identifier hs-type">Int64</span></a></span><span>
</span><span id="line-204"></span><span id="getAllocationCounter"><span class="annot"><span class="annottext">getAllocationCounter :: IO Int64
</span><a href="GHC.Conc.Sync.html#getAllocationCounter"><span class="hs-identifier hs-var hs-var">getAllocationCounter</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Int64 #)) -&gt; IO Int64
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Int64 #)) -&gt; IO Int64)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Int64 #)) -&gt; IO Int64
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539729"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539729"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-205"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.Ext.html#getThreadAllocationCounter%23"><span class="hs-identifier hs-var">getThreadAllocationCounter#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539729"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539727"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539727"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539726"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539726"><span class="hs-identifier hs-var">ctr</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539727"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int64
</span><a href="GHC.Int.html#I64%23"><span class="hs-identifier hs-var">I64#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539726"><span class="hs-identifier hs-var">ctr</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-206"></span><span>
</span><span id="line-207"></span><span class="hs-comment">-- | Enables the allocation counter to be treated as a limit for the</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- current thread.  When the allocation limit is enabled, if the</span><span>
</span><span id="line-209"></span><span class="hs-comment">-- allocation counter counts down below zero, the thread will be sent</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- the 'AllocationLimitExceeded' asynchronous exception.  When this</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- happens, the counter is reinitialised (by default</span><span>
</span><span id="line-212"></span><span class="hs-comment">-- to 100K, but tunable with the @+RTS -xq@ option) so that it can handle</span><span>
</span><span id="line-213"></span><span class="hs-comment">-- the exception and perform any necessary clean up.  If it exhausts</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- this additional allowance, another 'AllocationLimitExceeded' exception</span><span>
</span><span id="line-215"></span><span class="hs-comment">-- is sent, and so forth.  Like other asynchronous exceptions, the</span><span>
</span><span id="line-216"></span><span class="hs-comment">-- 'AllocationLimitExceeded' exception is deferred while the thread is inside</span><span>
</span><span id="line-217"></span><span class="hs-comment">-- 'mask' or an exception handler in 'catch'.</span><span>
</span><span id="line-218"></span><span class="hs-comment">--</span><span>
</span><span id="line-219"></span><span class="hs-comment">-- Note that memory allocation is unrelated to /live memory/, also</span><span>
</span><span id="line-220"></span><span class="hs-comment">-- known as /heap residency/.  A thread can allocate a large amount of</span><span>
</span><span id="line-221"></span><span class="hs-comment">-- memory and retain anything between none and all of it.  It is</span><span>
</span><span id="line-222"></span><span class="hs-comment">-- better to think of the allocation limit as a limit on</span><span>
</span><span id="line-223"></span><span class="hs-comment">-- /CPU time/, rather than a limit on memory.</span><span>
</span><span id="line-224"></span><span class="hs-comment">--</span><span>
</span><span id="line-225"></span><span class="hs-comment">-- Compared to using timeouts, allocation limits don't count time</span><span>
</span><span id="line-226"></span><span class="hs-comment">-- spent blocked or in foreign calls.</span><span>
</span><span id="line-227"></span><span class="hs-comment">--</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-229"></span><span class="annot"><a href="GHC.Conc.Sync.html#enableAllocationLimit"><span class="hs-identifier hs-type">enableAllocationLimit</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-230"></span><span id="enableAllocationLimit"><span class="annot"><span class="annottext">enableAllocationLimit :: IO ()
</span><a href="GHC.Conc.Sync.html#enableAllocationLimit"><span class="hs-identifier hs-var hs-var">enableAllocationLimit</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-231"></span><span>  </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539725"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539725"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO ThreadId
</span><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-var">myThreadId</span></a></span><span>
</span><span id="line-232"></span><span>  </span><span class="annot"><span class="annottext">ThreadId# -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#rts_enableThreadAllocationLimit"><span class="hs-identifier hs-var">rts_enableThreadAllocationLimit</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539725"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-233"></span><span>
</span><span id="line-234"></span><span class="hs-comment">-- | Disable allocation limit processing for the current thread.</span><span>
</span><span id="line-235"></span><span class="hs-comment">--</span><span>
</span><span id="line-236"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-237"></span><span class="annot"><a href="GHC.Conc.Sync.html#disableAllocationLimit"><span class="hs-identifier hs-type">disableAllocationLimit</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-238"></span><span id="disableAllocationLimit"><span class="annot"><span class="annottext">disableAllocationLimit :: IO ()
</span><a href="GHC.Conc.Sync.html#disableAllocationLimit"><span class="hs-identifier hs-var hs-var">disableAllocationLimit</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-239"></span><span>  </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539723"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539723"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO ThreadId
</span><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-var">myThreadId</span></a></span><span>
</span><span id="line-240"></span><span>  </span><span class="annot"><span class="annottext">ThreadId# -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#rts_disableThreadAllocationLimit"><span class="hs-identifier hs-var">rts_disableThreadAllocationLimit</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539723"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-241"></span><span>
</span><span id="line-242"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;rts_enableThreadAllocationLimit&quot;</span></span><span>
</span><span id="line-243"></span><span>  </span><span id="rts_enableThreadAllocationLimit"><span class="annot"><a href="GHC.Conc.Sync.html#rts_enableThreadAllocationLimit"><span class="hs-identifier hs-var">rts_enableThreadAllocationLimit</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;rts_disableThreadAllocationLimit&quot;</span></span><span>
</span><span id="line-246"></span><span>  </span><span id="rts_disableThreadAllocationLimit"><span class="annot"><a href="GHC.Conc.Sync.html#rts_disableThreadAllocationLimit"><span class="hs-identifier hs-var">rts_disableThreadAllocationLimit</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-247"></span><span>
</span><span id="line-248"></span><span class="hs-comment">{- |
Creates a new thread to run the 'IO' computation passed as the
first argument, and returns the 'ThreadId' of the newly created
thread.

The new thread will be a lightweight, /unbound/ thread.  Foreign calls
made by this thread are not guaranteed to be made by any particular OS
thread; if you need foreign calls to be made by a particular OS
thread, then use 'Control.Concurrent.forkOS' instead.

The new thread inherits the /masked/ state of the parent (see
'Control.Exception.mask').

The newly created thread has an exception handler that discards the
exceptions 'BlockedIndefinitelyOnMVar', 'BlockedIndefinitelyOnSTM', and
'ThreadKilled', and passes all other exceptions to the uncaught
exception handler.
-}</span><span>
</span><span id="line-266"></span><span class="annot"><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-type">forkIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-267"></span><span id="forkIO"><span class="annot"><span class="annottext">forkIO :: IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-var hs-var">forkIO</span></a></span></span><span> </span><span id="local-6989586621679539721"><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539721"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
 -&gt; IO ThreadId)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679539720"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539720"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-268"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO () -&gt; State# RealWorld -&gt; (# State# RealWorld, ThreadId# #)
forall a.
a -&gt; State# RealWorld -&gt; (# State# RealWorld, ThreadId# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#fork%23"><span class="hs-identifier hs-var">fork#</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539719"><span class="hs-identifier hs-var">action_plus</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539720"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539718"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539718"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539717"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539717"><span class="hs-identifier hs-var">tid</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539718"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; ThreadId
</span><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-var">ThreadId</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539717"><span class="hs-identifier hs-var">tid</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-269"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-270"></span><span>  </span><span class="hs-comment">-- We must use 'catch' rather than 'catchException' because the action</span><span>
</span><span id="line-271"></span><span>  </span><span class="hs-comment">-- could be bottom. #13330</span><span>
</span><span id="line-272"></span><span>  </span><span id="local-6989586621679539719"><span class="annot"><span class="annottext">action_plus :: IO ()
</span><a href="#local-6989586621679539719"><span class="hs-identifier hs-var hs-var">action_plus</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (SomeException -&gt; IO ()) -&gt; IO ()
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">catch</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539721"><span class="hs-identifier hs-var">action</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier hs-var">childHandler</span></a></span><span>
</span><span id="line-273"></span><span>
</span><span id="line-274"></span><span class="hs-comment">-- | Like 'forkIO', but the child thread is passed a function that can</span><span>
</span><span id="line-275"></span><span class="hs-comment">-- be used to unmask asynchronous exceptions.  This function is</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- typically used in the following way</span><span>
</span><span id="line-277"></span><span class="hs-comment">--</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- &gt;  ... mask_ $ forkIOWithUnmask $ \unmask -&gt;</span><span>
</span><span id="line-279"></span><span class="hs-comment">-- &gt;                 catch (unmask ...) handler</span><span>
</span><span id="line-280"></span><span class="hs-comment">--</span><span>
</span><span id="line-281"></span><span class="hs-comment">-- so that the exception handler in the child thread is established</span><span>
</span><span id="line-282"></span><span class="hs-comment">-- with asynchronous exceptions masked, meanwhile the main body of</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- the child thread is executed in the unmasked state.</span><span>
</span><span id="line-284"></span><span class="hs-comment">--</span><span>
</span><span id="line-285"></span><span class="hs-comment">-- Note that the unmask function passed to the child thread should</span><span>
</span><span id="line-286"></span><span class="hs-comment">-- only be used in that thread; the behaviour is undefined if it is</span><span>
</span><span id="line-287"></span><span class="hs-comment">-- invoked in a different thread.</span><span>
</span><span id="line-288"></span><span class="hs-comment">--</span><span>
</span><span id="line-289"></span><span class="hs-comment">-- @since 4.4.0.0</span><span>
</span><span id="line-290"></span><span class="annot"><a href="GHC.Conc.Sync.html#forkIOWithUnmask"><span class="hs-identifier hs-type">forkIOWithUnmask</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679540094"><span class="annot"><a href="#local-6989586621679540094"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540094"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540094"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-291"></span><span id="forkIOWithUnmask"><span class="annot"><span class="annottext">forkIOWithUnmask :: ((forall a. IO a -&gt; IO a) -&gt; IO ()) -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIOWithUnmask"><span class="hs-identifier hs-var hs-var">forkIOWithUnmask</span></a></span></span><span> </span><span id="local-6989586621679539714"><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO ()
</span><a href="#local-6989586621679539714"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-var">forkIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO ()
</span><a href="#local-6989586621679539714"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-var">unsafeUnmask</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-292"></span><span>
</span><span id="line-293"></span><span class="hs-comment">{- |
Like 'forkIO', but lets you specify on which capability the thread
should run.  Unlike a `forkIO` thread, a thread created by `forkOn`
will stay on the same capability for its entire lifetime (`forkIO`
threads can migrate between capabilities according to the scheduling
policy).  `forkOn` is useful for overriding the scheduling policy when
you know in advance how best to distribute the threads.

The `Int` argument specifies a /capability number/ (see
'getNumCapabilities').  Typically capabilities correspond to physical
processors, but the exact behaviour is implementation-dependent.  The
value passed to 'forkOn' is interpreted modulo the total number of
capabilities as returned by 'getNumCapabilities'.

GHC note: the number of capabilities is specified by the @+RTS -N@
option when the program is started.  Capabilities can be fixed to
actual processor cores with @+RTS -qa@ if the underlying operating
system supports that, although in practice this is usually unnecessary
(and may actually degrade performance in some cases - experimentation
is recommended).

@since 4.4.0.0
-}</span><span>
</span><span id="line-316"></span><span class="annot"><a href="GHC.Conc.Sync.html#forkOn"><span class="hs-identifier hs-type">forkOn</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-317"></span><span id="forkOn"><span class="annot"><span class="annottext">forkOn :: Int -&gt; IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkOn"><span class="hs-identifier hs-var hs-var">forkOn</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679539712"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539712"><span class="hs-identifier hs-var">cpu</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539711"><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539711"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
 -&gt; IO ThreadId)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679539710"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539710"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-318"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int#
-&gt; IO () -&gt; State# RealWorld -&gt; (# State# RealWorld, ThreadId# #)
forall a.
Int# -&gt; a -&gt; State# RealWorld -&gt; (# State# RealWorld, ThreadId# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#forkOn%23"><span class="hs-identifier hs-var">forkOn#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539712"><span class="hs-identifier hs-var">cpu</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539709"><span class="hs-identifier hs-var">action_plus</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539710"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539708"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539708"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539707"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539707"><span class="hs-identifier hs-var">tid</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539708"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; ThreadId
</span><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-var">ThreadId</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539707"><span class="hs-identifier hs-var">tid</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-319"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-320"></span><span>  </span><span class="hs-comment">-- We must use 'catch' rather than 'catchException' because the action</span><span>
</span><span id="line-321"></span><span>  </span><span class="hs-comment">-- could be bottom. #13330</span><span>
</span><span id="line-322"></span><span>  </span><span id="local-6989586621679539709"><span class="annot"><span class="annottext">action_plus :: IO ()
</span><a href="#local-6989586621679539709"><span class="hs-identifier hs-var hs-var">action_plus</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (SomeException -&gt; IO ()) -&gt; IO ()
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">catch</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679539711"><span class="hs-identifier hs-var">action</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier hs-var">childHandler</span></a></span><span>
</span><span id="line-323"></span><span>
</span><span id="line-324"></span><span class="hs-comment">-- | Like 'forkIOWithUnmask', but the child thread is pinned to the</span><span>
</span><span id="line-325"></span><span class="hs-comment">-- given CPU, as with 'forkOn'.</span><span>
</span><span id="line-326"></span><span class="hs-comment">--</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- @since 4.4.0.0</span><span>
</span><span id="line-328"></span><span class="annot"><a href="GHC.Conc.Sync.html#forkOnWithUnmask"><span class="hs-identifier hs-type">forkOnWithUnmask</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679539705"><span class="annot"><a href="#local-6989586621679539705"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539705"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539705"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-329"></span><span id="forkOnWithUnmask"><span class="annot"><span class="annottext">forkOnWithUnmask :: Int -&gt; ((forall a. IO a -&gt; IO a) -&gt; IO ()) -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkOnWithUnmask"><span class="hs-identifier hs-var hs-var">forkOnWithUnmask</span></a></span></span><span> </span><span id="local-6989586621679539704"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539704"><span class="hs-identifier hs-var">cpu</span></a></span></span><span> </span><span id="local-6989586621679539703"><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO ()
</span><a href="#local-6989586621679539703"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkOn"><span class="hs-identifier hs-var">forkOn</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539704"><span class="hs-identifier hs-var">cpu</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO ()
</span><a href="#local-6989586621679539703"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-var">unsafeUnmask</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-330"></span><span>
</span><span id="line-331"></span><span class="hs-comment">-- | the value passed to the @+RTS -N@ flag.  This is the number of</span><span>
</span><span id="line-332"></span><span class="hs-comment">-- Haskell threads that can run truly simultaneously at any given</span><span>
</span><span id="line-333"></span><span class="hs-comment">-- time, and is typically set to the number of physical processor cores on</span><span>
</span><span id="line-334"></span><span class="hs-comment">-- the machine.</span><span>
</span><span id="line-335"></span><span class="hs-comment">--</span><span>
</span><span id="line-336"></span><span class="hs-comment">-- Strictly speaking it is better to use 'getNumCapabilities', because</span><span>
</span><span id="line-337"></span><span class="hs-comment">-- the number of capabilities might vary at runtime.</span><span>
</span><span id="line-338"></span><span class="hs-comment">--</span><span>
</span><span id="line-339"></span><span class="annot"><a href="GHC.Conc.Sync.html#numCapabilities"><span class="hs-identifier hs-type">numCapabilities</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-340"></span><span id="numCapabilities"><span class="annot"><span class="annottext">numCapabilities :: Int
</span><a href="GHC.Conc.Sync.html#numCapabilities"><span class="hs-identifier hs-var hs-var">numCapabilities</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Int -&gt; Int
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Int -&gt; Int) -&gt; IO Int -&gt; Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO Int
</span><a href="GHC.Conc.Sync.html#getNumCapabilities"><span class="hs-identifier hs-var">getNumCapabilities</span></a></span><span>
</span><span id="line-341"></span><span>
</span><span id="line-342"></span><span class="hs-comment">{- |
Returns the number of Haskell threads that can run truly
simultaneously (on separate physical processors) at any given time.  To change
this value, use 'setNumCapabilities'.

@since 4.4.0.0
-}</span><span>
</span><span id="line-349"></span><span class="annot"><a href="GHC.Conc.Sync.html#getNumCapabilities"><span class="hs-identifier hs-type">getNumCapabilities</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-350"></span><span id="getNumCapabilities"><span class="annot"><span class="annottext">getNumCapabilities :: IO Int
</span><a href="GHC.Conc.Sync.html#getNumCapabilities"><span class="hs-identifier hs-var hs-var">getNumCapabilities</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-351"></span><span>   </span><span id="local-6989586621679539701"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679539701"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CInt -&gt; IO CInt
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CInt
</span><a href="GHC.Conc.Sync.html#enabled_capabilities"><span class="hs-identifier hs-var">enabled_capabilities</span></a></span><span>
</span><span id="line-352"></span><span>   </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CInt -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679539701"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-353"></span><span>
</span><span id="line-354"></span><span class="hs-comment">{- |
Set the number of Haskell threads that can run truly simultaneously
(on separate physical processors) at any given time.  The number
passed to `forkOn` is interpreted modulo this value.  The initial
value is given by the @+RTS -N@ runtime flag.

This is also the number of threads that will participate in parallel
garbage collection.  It is strongly recommended that the number of
capabilities is not set larger than the number of physical processor
cores, and it may often be beneficial to leave one or more cores free
to avoid contention with other processes in the machine.

@since 4.5.0.0
-}</span><span>
</span><span id="line-368"></span><span class="annot"><a href="GHC.Conc.Sync.html#setNumCapabilities"><span class="hs-identifier hs-type">setNumCapabilities</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-369"></span><span id="setNumCapabilities"><span class="annot"><span class="annottext">setNumCapabilities :: Int -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#setNumCapabilities"><span class="hs-identifier hs-var hs-var">setNumCapabilities</span></a></span></span><span> </span><span id="local-6989586621679539698"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539698"><span class="hs-identifier hs-var">i</span></a></span></span><span>
</span><span id="line-370"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539698"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; IO a
</span><a href="GHC.Base.html#failIO"><span class="hs-identifier hs-var">failIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setNumCapabilities: Capability count (&quot;</span></span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539698"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;) must be positive&quot;</span></span><span>
</span><span id="line-371"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CUInt -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#c_setNumCapabilities"><span class="hs-identifier hs-var">c_setNumCapabilities</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CUInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679539698"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-372"></span><span>
</span><span id="line-373"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">safe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;setNumCapabilities&quot;</span></span><span>
</span><span id="line-374"></span><span>  </span><span id="c_setNumCapabilities"><span class="annot"><a href="GHC.Conc.Sync.html#c_setNumCapabilities"><span class="hs-identifier hs-var">c_setNumCapabilities</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CUInt"><span class="hs-identifier hs-type">CUInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-375"></span><span>
</span><span id="line-376"></span><span class="hs-comment">-- | Returns the number of CPUs that the machine has</span><span>
</span><span id="line-377"></span><span class="hs-comment">--</span><span>
</span><span id="line-378"></span><span class="hs-comment">-- @since 4.5.0.0</span><span>
</span><span id="line-379"></span><span class="annot"><a href="GHC.Conc.Sync.html#getNumProcessors"><span class="hs-identifier hs-type">getNumProcessors</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-380"></span><span id="getNumProcessors"><span class="annot"><span class="annottext">getNumProcessors :: IO Int
</span><a href="GHC.Conc.Sync.html#getNumProcessors"><span class="hs-identifier hs-var hs-var">getNumProcessors</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CUInt -&gt; Int) -&gt; IO CUInt -&gt; IO Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">CUInt -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">IO CUInt
</span><a href="GHC.Conc.Sync.html#c_getNumberOfProcessors"><span class="hs-identifier hs-var">c_getNumberOfProcessors</span></a></span><span>
</span><span id="line-381"></span><span>
</span><span id="line-382"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getNumberOfProcessors&quot;</span></span><span>
</span><span id="line-383"></span><span>  </span><span id="c_getNumberOfProcessors"><span class="annot"><a href="GHC.Conc.Sync.html#c_getNumberOfProcessors"><span class="hs-identifier hs-var">c_getNumberOfProcessors</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CUInt"><span class="hs-identifier hs-type">CUInt</span></a></span><span>
</span><span id="line-384"></span><span>
</span><span id="line-385"></span><span class="hs-comment">-- | Returns the number of sparks currently in the local spark pool</span><span>
</span><span id="line-386"></span><span class="annot"><a href="GHC.Conc.Sync.html#numSparks"><span class="hs-identifier hs-type">numSparks</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-387"></span><span id="numSparks"><span class="annot"><span class="annottext">numSparks :: IO Int
</span><a href="GHC.Conc.Sync.html#numSparks"><span class="hs-identifier hs-var hs-var">numSparks</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Int #)) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539693"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539693"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, Int# #)
forall d. State# d -&gt; (# State# d, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#numSparks%23"><span class="hs-identifier hs-var">numSparks#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539693"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539692"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539692"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539691"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539691"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539692"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539691"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-388"></span><span>
</span><span id="line-389"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-string">&quot;&amp;enabled_capabilities&quot;</span></span><span> </span><span id="enabled_capabilities"><span class="annot"><a href="GHC.Conc.Sync.html#enabled_capabilities"><span class="hs-identifier hs-var">enabled_capabilities</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-390"></span><span>
</span><span id="line-391"></span><span class="annot"><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier hs-type">childHandler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-392"></span><span id="childHandler"><span class="annot"><span class="annottext">childHandler :: SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier hs-var hs-var">childHandler</span></a></span></span><span> </span><span id="local-6989586621679539690"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539690"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (SomeException -&gt; IO ()) -&gt; IO ()
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">catch</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#real_handler"><span class="hs-identifier hs-var">real_handler</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539690"><span class="hs-identifier hs-var">err</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#childHandler"><span class="hs-identifier hs-var">childHandler</span></a></span><span>
</span><span id="line-393"></span><span>  </span><span class="hs-comment">-- We must use catch here rather than catchException. If the</span><span>
</span><span id="line-394"></span><span>  </span><span class="hs-comment">-- raised exception throws an (imprecise) exception, then real_handler err</span><span>
</span><span id="line-395"></span><span>  </span><span class="hs-comment">-- will do so as well. If we use catchException here, then we could miss</span><span>
</span><span id="line-396"></span><span>  </span><span class="hs-comment">-- that exception.</span><span>
</span><span id="line-397"></span><span>
</span><span id="line-398"></span><span class="annot"><a href="GHC.Conc.Sync.html#real_handler"><span class="hs-identifier hs-type">real_handler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-399"></span><span id="real_handler"><span class="annot"><span class="annottext">real_handler :: SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#real_handler"><span class="hs-identifier hs-var hs-var">real_handler</span></a></span></span><span> </span><span id="local-6989586621679539688"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span></span><span>
</span><span id="line-400"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">BlockedIndefinitelyOnMVar
</span><a href="GHC.IO.Exception.html#BlockedIndefinitelyOnMVar"><span class="hs-identifier hs-var">BlockedIndefinitelyOnMVar</span></a></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe BlockedIndefinitelyOnMVar
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-401"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">BlockedIndefinitelyOnSTM
</span><a href="GHC.IO.Exception.html#BlockedIndefinitelyOnSTM"><span class="hs-identifier hs-var">BlockedIndefinitelyOnSTM</span></a></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe BlockedIndefinitelyOnSTM
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-402"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">AsyncException
</span><a href="GHC.IO.Exception.html#ThreadKilled"><span class="hs-identifier hs-var">ThreadKilled</span></a></span><span>              </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe AsyncException
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-403"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">AsyncException
</span><a href="GHC.IO.Exception.html#StackOverflow"><span class="hs-identifier hs-var">StackOverflow</span></a></span><span>             </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe AsyncException
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.Sync.html#reportStackOverflow"><span class="hs-identifier hs-var">reportStackOverflow</span></a></span><span>
</span><span id="line-404"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                                           </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#reportError"><span class="hs-identifier hs-var">reportError</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539688"><span class="hs-identifier hs-var">se</span></a></span><span>
</span><span id="line-405"></span><span>
</span><span id="line-406"></span><span class="hs-comment">{- | 'killThread' raises the 'ThreadKilled' exception in the given
thread (GHC only).

&gt; killThread tid = throwTo tid ThreadKilled

-}</span><span>
</span><span id="line-412"></span><span class="annot"><a href="GHC.Conc.Sync.html#killThread"><span class="hs-identifier hs-type">killThread</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-413"></span><span id="killThread"><span class="annot"><span class="annottext">killThread :: ThreadId -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#killThread"><span class="hs-identifier hs-var hs-var">killThread</span></a></span></span><span> </span><span id="local-6989586621679539682"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679539682"><span class="hs-identifier hs-var">tid</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId -&gt; AsyncException -&gt; IO ()
forall e. Exception e =&gt; ThreadId -&gt; e -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#throwTo"><span class="hs-identifier hs-var">throwTo</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679539682"><span class="hs-identifier hs-var">tid</span></a></span><span> </span><span class="annot"><span class="annottext">AsyncException
</span><a href="GHC.IO.Exception.html#ThreadKilled"><span class="hs-identifier hs-var">ThreadKilled</span></a></span><span>
</span><span id="line-414"></span><span>
</span><span id="line-415"></span><span class="hs-comment">{- | 'throwTo' raises an arbitrary exception in the target thread (GHC only).

Exception delivery synchronizes between the source and target thread:
'throwTo' does not return until the exception has been raised in the
target thread. The calling thread can thus be certain that the target
thread has received the exception.  Exception delivery is also atomic
with respect to other exceptions. Atomicity is a useful property to have
when dealing with race conditions: e.g. if there are two threads that
can kill each other, it is guaranteed that only one of the threads
will get to kill the other.

Whatever work the target thread was doing when the exception was
raised is not lost: the computation is suspended until required by
another thread.

If the target thread is currently making a foreign call, then the
exception will not be raised (and hence 'throwTo' will not return)
until the call has completed.  This is the case regardless of whether
the call is inside a 'mask' or not.  However, in GHC a foreign call
can be annotated as @interruptible@, in which case a 'throwTo' will
cause the RTS to attempt to cause the call to return; see the GHC
documentation for more details.

Important note: the behaviour of 'throwTo' differs from that described in
the paper \&quot;Asynchronous exceptions in Haskell\&quot;
(&lt;http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm&gt;).
In the paper, 'throwTo' is non-blocking; but the library implementation adopts
a more synchronous design in which 'throwTo' does not return until the exception
is received by the target thread.  The trade-off is discussed in Section 9 of the paper.
Like any blocking operation, 'throwTo' is therefore interruptible (see Section 5.3 of
the paper).  Unlike other interruptible operations, however, 'throwTo'
is /always/ interruptible, even if it does not actually block.

There is no guarantee that the exception will be delivered promptly,
although the runtime will endeavour to ensure that arbitrary
delays don't occur.  In GHC, an exception can only be raised when a
thread reaches a /safe point/, where a safe point is where memory
allocation occurs.  Some loops do not perform any memory allocation
inside the loop and therefore cannot be interrupted by a 'throwTo'.

If the target of 'throwTo' is the calling thread, then the behaviour
is the same as 'Control.Exception.throwIO', except that the exception
is thrown as an asynchronous exception.  This means that if there is
an enclosing pure computation, which would be the case if the current
IO operation is inside 'unsafePerformIO' or 'unsafeInterleaveIO', that
computation is not permanently replaced by the exception, but is
suspended as if it had received an asynchronous exception.

Note that if 'throwTo' is called with the current thread as the
target, the exception will be thrown even if the thread is currently
inside 'mask' or 'uninterruptibleMask'.
  -}</span><span>
</span><span id="line-467"></span><span id="local-6989586621679540080"><span class="annot"><a href="GHC.Conc.Sync.html#throwTo"><span class="hs-identifier hs-type">throwTo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540080"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679540080"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-468"></span><span id="throwTo"><span class="annot"><span class="annottext">throwTo :: forall e. Exception e =&gt; ThreadId -&gt; e -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#throwTo"><span class="hs-identifier hs-var hs-var">throwTo</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539679"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539679"><span class="hs-identifier hs-var">tid</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539678"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539678"><span class="hs-identifier hs-var">ex</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679539677"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539677"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-469"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadId# -&gt; SomeException -&gt; State# RealWorld -&gt; State# RealWorld
forall a. ThreadId# -&gt; a -&gt; State# RealWorld -&gt; State# RealWorld
</span><a href="../../ghc-prim/src/GHC.Prim.html#killThread%23"><span class="hs-identifier hs-var">killThread#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539679"><span class="hs-identifier hs-var">tid</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; SomeException
forall e. Exception e =&gt; e -&gt; SomeException
</span><a href="GHC.Exception.Type.html#toException"><span class="hs-identifier hs-var">toException</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539678"><span class="hs-identifier hs-var">ex</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539677"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span id="local-6989586621679539675"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539675"><span class="hs-identifier hs-var">s1</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539675"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-470"></span><span>
</span><span id="line-471"></span><span class="hs-comment">-- | Returns the 'ThreadId' of the calling thread (GHC only).</span><span>
</span><span id="line-472"></span><span class="annot"><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-type">myThreadId</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-473"></span><span id="myThreadId"><span class="annot"><span class="annottext">myThreadId :: IO ThreadId
</span><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-var hs-var">myThreadId</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
 -&gt; IO ThreadId)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, ThreadId #))
-&gt; IO ThreadId
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539674"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539674"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-474"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, ThreadId# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#myThreadId%23"><span class="hs-identifier hs-var">myThreadId#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539674"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539673"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539673"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539672"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539672"><span class="hs-identifier hs-var">tid</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539673"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; ThreadId
</span><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-var">ThreadId</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539672"><span class="hs-identifier hs-var">tid</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-475"></span><span>
</span><span id="line-476"></span><span>
</span><span id="line-477"></span><span class="hs-comment">-- | The 'yield' action allows (forces, in a co-operative multitasking</span><span>
</span><span id="line-478"></span><span class="hs-comment">-- implementation) a context-switch to any other currently runnable</span><span>
</span><span id="line-479"></span><span class="hs-comment">-- threads (if any), and is occasionally useful when implementing</span><span>
</span><span id="line-480"></span><span class="hs-comment">-- concurrency abstractions.</span><span>
</span><span id="line-481"></span><span class="annot"><a href="GHC.Conc.Sync.html#yield"><span class="hs-identifier hs-type">yield</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-482"></span><span id="yield"><span class="annot"><span class="annottext">yield :: IO ()
</span><a href="GHC.Conc.Sync.html#yield"><span class="hs-identifier hs-var hs-var">yield</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539671"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539671"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-483"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">State# RealWorld -&gt; State# RealWorld
</span><a href="../../ghc-prim/src/GHC.Prim.html#yield%23"><span class="hs-identifier hs-var">yield#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539671"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span id="local-6989586621679539670"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539670"><span class="hs-identifier hs-var">s1</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539670"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-484"></span><span>
</span><span id="line-485"></span><span class="hs-comment">{- | 'labelThread' stores a string as identifier for this thread if
you built a RTS with debugging support. This identifier will be used in
the debugging output to make distinction of different threads easier
(otherwise you only have the thread state object\'s address in the heap).

Other applications like the graphical Concurrent Haskell Debugger
(&lt;http://www.informatik.uni-kiel.de/~fhu/chd/&gt;) may choose to overload
'labelThread' for their purposes as well.
-}</span><span>
</span><span id="line-494"></span><span>
</span><span id="line-495"></span><span class="annot"><a href="GHC.Conc.Sync.html#labelThread"><span class="hs-identifier hs-type">labelThread</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-496"></span><span id="labelThread"><span class="annot"><span class="annottext">labelThread :: ThreadId -&gt; String -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#labelThread"><span class="hs-identifier hs-var hs-var">labelThread</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539669"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539669"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539668"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679539668"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-497"></span><span>    </span><span class="annot"><span class="annottext">TextEncoding -&gt; String -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a. TextEncoding -&gt; String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="GHC.Foreign.html#withCString"><span class="hs-identifier hs-var">GHC.Foreign.withCString</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="GHC.IO.Encoding.UTF8.html#utf8"><span class="hs-identifier hs-var">utf8</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679539668"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO ()) -&gt; IO ()) -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span id="local-6989586621679539664"><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679539664"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-498"></span><span>    </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679539663"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539663"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-499"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadId# -&gt; Addr# -&gt; State# RealWorld -&gt; State# RealWorld
</span><a href="../../ghc-prim/src/GHC.Prim.html#labelThread%23"><span class="hs-identifier hs-var">labelThread#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539669"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Addr#
</span><a href="#local-6989586621679539664"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539663"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span id="local-6989586621679539662"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539662"><span class="hs-identifier hs-var">s1</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539662"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-500"></span><span>
</span><span id="line-501"></span><span class="hs-comment">--      Nota Bene: 'pseq' used to be 'seq'</span><span>
</span><span id="line-502"></span><span class="hs-comment">--                 but 'seq' is now defined in PrelGHC</span><span>
</span><span id="line-503"></span><span class="hs-comment">--</span><span>
</span><span id="line-504"></span><span class="hs-comment">-- &quot;pseq&quot; is defined a bit weirdly (see below)</span><span>
</span><span id="line-505"></span><span class="hs-comment">--</span><span>
</span><span id="line-506"></span><span class="hs-comment">-- The reason for the strange &quot;lazy&quot; call is that</span><span>
</span><span id="line-507"></span><span class="hs-comment">-- it fools the compiler into thinking that pseq  and par are non-strict in</span><span>
</span><span id="line-508"></span><span class="hs-comment">-- their second argument (even if it inlines pseq at the call site).</span><span>
</span><span id="line-509"></span><span class="hs-comment">-- If it thinks pseq is strict in &quot;y&quot;, then it often evaluates</span><span>
</span><span id="line-510"></span><span class="hs-comment">-- &quot;y&quot; before &quot;x&quot;, which is totally wrong.</span><span>
</span><span id="line-511"></span><span>
</span><span id="line-512"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#pseq"><span class="hs-pragma hs-type">pseq</span></a></span><span>  </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-513"></span><span id="local-6989586621679540074"><span id="local-6989586621679540075"><span class="annot"><a href="GHC.Conc.Sync.html#pseq"><span class="hs-identifier hs-type">pseq</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679540075"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679540074"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679540074"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-514"></span><span id="pseq"><span class="annot"><span class="annottext">pseq :: forall a b. a -&gt; b -&gt; b
</span><a href="GHC.Conc.Sync.html#pseq"><span class="hs-identifier hs-var hs-var">pseq</span></a></span></span><span>  </span><span id="local-6989586621679539661"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539661"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679539660"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539660"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539661"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b -&gt; b
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; b
forall a. a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Magic.html#lazy"><span class="hs-identifier hs-var">lazy</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539660"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-515"></span><span>
</span><span id="line-516"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#par"><span class="hs-pragma hs-type">par</span></a></span><span>  </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-517"></span><span id="local-6989586621679539658"><span id="local-6989586621679539659"><span class="annot"><a href="GHC.Conc.Sync.html#par"><span class="hs-identifier hs-type">par</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679539659"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679539658"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679539658"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-518"></span><span id="par"><span class="annot"><span class="annottext">par :: forall a b. a -&gt; b -&gt; b
</span><a href="GHC.Conc.Sync.html#par"><span class="hs-identifier hs-var hs-var">par</span></a></span></span><span>  </span><span id="local-6989586621679539657"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539657"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679539656"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539656"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int#
forall a. a -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#par%23"><span class="hs-identifier hs-var">par#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539657"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; b
forall a. a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Magic.html#lazy"><span class="hs-identifier hs-var">lazy</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539656"><span class="hs-identifier hs-var">y</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-519"></span><span>
</span><span id="line-520"></span><span class="hs-comment">-- | Internal function used by the RTS to run sparks.</span><span>
</span><span id="line-521"></span><span class="annot"><a href="GHC.Conc.Sync.html#runSparks"><span class="hs-identifier hs-type">runSparks</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-522"></span><span id="runSparks"><span class="annot"><span class="annottext">runSparks :: IO ()
</span><a href="GHC.Conc.Sync.html#runSparks"><span class="hs-identifier hs-var hs-var">runSparks</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, () #)
forall {d}. State# d -&gt; (# State# d, () #)
</span><a href="#local-6989586621679539655"><span class="hs-identifier hs-var">loop</span></a></span><span>
</span><span id="line-523"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679539655"><span class="annot"><span class="annottext">loop :: State# d -&gt; (# State# d, () #)
</span><a href="#local-6989586621679539655"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679539654"><span class="annot"><span class="annottext">State# d
</span><a href="#local-6989586621679539654"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# d -&gt; (# State# d, Int#, Any #)
forall d a. State# d -&gt; (# State# d, Int#, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#getSpark%23"><span class="hs-identifier hs-var">getSpark#</span></a></span><span> </span><span class="annot"><span class="annottext">State# d
</span><a href="#local-6989586621679539654"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-524"></span><span>                   </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539653"><span class="annot"><span class="annottext">State# d
</span><a href="#local-6989586621679539653"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539652"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539652"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539651"><span class="annot"><span class="annottext">Any
</span><a href="#local-6989586621679539651"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-525"></span><span>                      </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#isTrue%23"><span class="hs-identifier hs-var">isTrue#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539652"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int# -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#%3D%3D%23"><span class="hs-operator hs-var">==#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-number">0#</span></span><span class="hs-special">)</span><span>
</span><span id="line-526"></span><span>                      </span><span class="hs-keyword">then</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# d
</span><a href="#local-6989586621679539653"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-527"></span><span>                      </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Any
</span><a href="#local-6989586621679539651"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Any -&gt; (# State# d, () #) -&gt; (# State# d, () #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="annot"><span class="annottext">State# d -&gt; (# State# d, () #)
</span><a href="#local-6989586621679539655"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">State# d
</span><a href="#local-6989586621679539653"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-528"></span><span>
</span><span id="line-529"></span><span class="hs-keyword">data</span><span> </span><span id="BlockReason"><span class="annot"><a href="GHC.Conc.Sync.html#BlockReason"><span class="hs-identifier hs-var">BlockReason</span></a></span></span><span>
</span><span id="line-530"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="BlockedOnMVar"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnMVar"><span class="hs-identifier hs-var">BlockedOnMVar</span></a></span></span><span>
</span><span id="line-531"></span><span>        </span><span class="hs-comment">-- ^blocked on 'MVar'</span><span>
</span><span id="line-532"></span><span>  </span><span class="hs-comment">{- possibly (see 'threadstatus' below):
  | BlockedOnMVarRead
        -- ^blocked on reading an empty 'MVar'
  -}</span><span>
</span><span id="line-536"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnBlackHole"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnBlackHole"><span class="hs-identifier hs-var">BlockedOnBlackHole</span></a></span></span><span>
</span><span id="line-537"></span><span>        </span><span class="hs-comment">-- ^blocked on a computation in progress by another thread</span><span>
</span><span id="line-538"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnException"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnException"><span class="hs-identifier hs-var">BlockedOnException</span></a></span></span><span>
</span><span id="line-539"></span><span>        </span><span class="hs-comment">-- ^blocked in 'throwTo'</span><span>
</span><span id="line-540"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnSTM"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnSTM"><span class="hs-identifier hs-var">BlockedOnSTM</span></a></span></span><span>
</span><span id="line-541"></span><span>        </span><span class="hs-comment">-- ^blocked in 'retry' in an STM transaction</span><span>
</span><span id="line-542"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnForeignCall"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnForeignCall"><span class="hs-identifier hs-var">BlockedOnForeignCall</span></a></span></span><span>
</span><span id="line-543"></span><span>        </span><span class="hs-comment">-- ^currently in a foreign call</span><span>
</span><span id="line-544"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnIOCompletion"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnIOCompletion"><span class="hs-identifier hs-var">BlockedOnIOCompletion</span></a></span></span><span>
</span><span id="line-545"></span><span>        </span><span class="hs-comment">-- ^currently blocked on an I/O Completion port</span><span>
</span><span id="line-546"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="BlockedOnOther"><span class="annot"><a href="GHC.Conc.Sync.html#BlockedOnOther"><span class="hs-identifier hs-var">BlockedOnOther</span></a></span></span><span>
</span><span id="line-547"></span><span>        </span><span class="hs-comment">-- ^blocked on some other resource.  Without @-threaded@,</span><span>
</span><span id="line-548"></span><span>        </span><span class="hs-comment">-- I\/O and 'Control.Concurrent.threadDelay' show up as</span><span>
</span><span id="line-549"></span><span>        </span><span class="hs-comment">-- 'BlockedOnOther', with @-threaded@ they show up as 'BlockedOnMVar'.</span><span>
</span><span id="line-550"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span> </span><span id="local-6989586621679539639"><span id="local-6989586621679539641"><span class="annot"><span class="annottext">BlockReason -&gt; BlockReason -&gt; Bool
(BlockReason -&gt; BlockReason -&gt; Bool)
-&gt; (BlockReason -&gt; BlockReason -&gt; Bool) -&gt; Eq BlockReason
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: BlockReason -&gt; BlockReason -&gt; Bool
$c/= :: BlockReason -&gt; BlockReason -&gt; Bool
== :: BlockReason -&gt; BlockReason -&gt; Bool
$c== :: BlockReason -&gt; BlockReason -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></a></span></span></span><span>   </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-551"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539620"><span id="local-6989586621679539622"><span id="local-6989586621679539625"><span id="local-6989586621679539628"><span id="local-6989586621679539631"><span id="local-6989586621679539633"><span id="local-6989586621679539635"><span class="annot"><span class="annottext">Eq BlockReason
Eq BlockReason
-&gt; (BlockReason -&gt; BlockReason -&gt; Ordering)
-&gt; (BlockReason -&gt; BlockReason -&gt; Bool)
-&gt; (BlockReason -&gt; BlockReason -&gt; Bool)
-&gt; (BlockReason -&gt; BlockReason -&gt; Bool)
-&gt; (BlockReason -&gt; BlockReason -&gt; Bool)
-&gt; (BlockReason -&gt; BlockReason -&gt; BlockReason)
-&gt; (BlockReason -&gt; BlockReason -&gt; BlockReason)
-&gt; Ord BlockReason
BlockReason -&gt; BlockReason -&gt; Bool
BlockReason -&gt; BlockReason -&gt; Ordering
BlockReason -&gt; BlockReason -&gt; BlockReason
forall a.
Eq a
-&gt; (a -&gt; a -&gt; Ordering)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; a)
-&gt; (a -&gt; a -&gt; a)
-&gt; Ord a
min :: BlockReason -&gt; BlockReason -&gt; BlockReason
$cmin :: BlockReason -&gt; BlockReason -&gt; BlockReason
max :: BlockReason -&gt; BlockReason -&gt; BlockReason
$cmax :: BlockReason -&gt; BlockReason -&gt; BlockReason
&gt;= :: BlockReason -&gt; BlockReason -&gt; Bool
$c&gt;= :: BlockReason -&gt; BlockReason -&gt; Bool
&gt; :: BlockReason -&gt; BlockReason -&gt; Bool
$c&gt; :: BlockReason -&gt; BlockReason -&gt; Bool
&lt;= :: BlockReason -&gt; BlockReason -&gt; Bool
$c&lt;= :: BlockReason -&gt; BlockReason -&gt; Bool
&lt; :: BlockReason -&gt; BlockReason -&gt; Bool
$c&lt; :: BlockReason -&gt; BlockReason -&gt; Bool
compare :: BlockReason -&gt; BlockReason -&gt; Ordering
$ccompare :: BlockReason -&gt; BlockReason -&gt; Ordering
</span><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Ord</span></a></span></span></span></span></span></span></span></span><span>  </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-552"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539614"><span id="local-6989586621679539616"><span id="local-6989586621679539618"><span class="annot"><span class="annottext">Int -&gt; BlockReason -&gt; ShowS
[BlockReason] -&gt; ShowS
BlockReason -&gt; String
(Int -&gt; BlockReason -&gt; ShowS)
-&gt; (BlockReason -&gt; String)
-&gt; ([BlockReason] -&gt; ShowS)
-&gt; Show BlockReason
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [BlockReason] -&gt; ShowS
$cshowList :: [BlockReason] -&gt; ShowS
show :: BlockReason -&gt; String
$cshow :: BlockReason -&gt; String
showsPrec :: Int -&gt; BlockReason -&gt; ShowS
$cshowsPrec :: Int -&gt; BlockReason -&gt; ShowS
</span><a href="GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-553"></span><span>           </span><span class="hs-special">)</span><span>
</span><span id="line-554"></span><span>
</span><span id="line-555"></span><span class="hs-comment">-- | The current status of a thread</span><span>
</span><span id="line-556"></span><span class="hs-keyword">data</span><span> </span><span id="ThreadStatus"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadStatus"><span class="hs-identifier hs-var">ThreadStatus</span></a></span></span><span>
</span><span id="line-557"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="ThreadRunning"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadRunning"><span class="hs-identifier hs-var">ThreadRunning</span></a></span></span><span>
</span><span id="line-558"></span><span>        </span><span class="hs-comment">-- ^the thread is currently runnable or running</span><span>
</span><span id="line-559"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ThreadFinished"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadFinished"><span class="hs-identifier hs-var">ThreadFinished</span></a></span></span><span>
</span><span id="line-560"></span><span>        </span><span class="hs-comment">-- ^the thread has finished</span><span>
</span><span id="line-561"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ThreadBlocked"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span></span><span>  </span><span class="annot"><a href="GHC.Conc.Sync.html#BlockReason"><span class="hs-identifier hs-type">BlockReason</span></a></span><span>
</span><span id="line-562"></span><span>        </span><span class="hs-comment">-- ^the thread is blocked on some resource</span><span>
</span><span id="line-563"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ThreadDied"><span class="annot"><a href="GHC.Conc.Sync.html#ThreadDied"><span class="hs-identifier hs-var">ThreadDied</span></a></span></span><span>
</span><span id="line-564"></span><span>        </span><span class="hs-comment">-- ^the thread received an uncaught exception</span><span>
</span><span id="line-565"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span> </span><span id="local-6989586621679539605"><span id="local-6989586621679539608"><span class="annot"><span class="annottext">ThreadStatus -&gt; ThreadStatus -&gt; Bool
(ThreadStatus -&gt; ThreadStatus -&gt; Bool)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Bool) -&gt; Eq ThreadStatus
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c/= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
== :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c== :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></a></span></span></span><span>   </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-566"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539588"><span id="local-6989586621679539590"><span id="local-6989586621679539592"><span id="local-6989586621679539594"><span id="local-6989586621679539596"><span id="local-6989586621679539598"><span id="local-6989586621679539601"><span class="annot"><span class="annottext">Eq ThreadStatus
Eq ThreadStatus
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Ordering)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Bool)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Bool)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Bool)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; Bool)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus)
-&gt; (ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus)
-&gt; Ord ThreadStatus
ThreadStatus -&gt; ThreadStatus -&gt; Bool
ThreadStatus -&gt; ThreadStatus -&gt; Ordering
ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus
forall a.
Eq a
-&gt; (a -&gt; a -&gt; Ordering)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; Bool)
-&gt; (a -&gt; a -&gt; a)
-&gt; (a -&gt; a -&gt; a)
-&gt; Ord a
min :: ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus
$cmin :: ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus
max :: ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus
$cmax :: ThreadStatus -&gt; ThreadStatus -&gt; ThreadStatus
&gt;= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c&gt;= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
&gt; :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c&gt; :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
&lt;= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c&lt;= :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
&lt; :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
$c&lt; :: ThreadStatus -&gt; ThreadStatus -&gt; Bool
compare :: ThreadStatus -&gt; ThreadStatus -&gt; Ordering
$ccompare :: ThreadStatus -&gt; ThreadStatus -&gt; Ordering
</span><a href="../../ghc-prim/src/GHC.Classes.html#Ord"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Ord</span></a></span></span></span></span></span></span></span></span><span>  </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-567"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539580"><span id="local-6989586621679539582"><span id="local-6989586621679539586"><span class="annot"><span class="annottext">Int -&gt; ThreadStatus -&gt; ShowS
[ThreadStatus] -&gt; ShowS
ThreadStatus -&gt; String
(Int -&gt; ThreadStatus -&gt; ShowS)
-&gt; (ThreadStatus -&gt; String)
-&gt; ([ThreadStatus] -&gt; ShowS)
-&gt; Show ThreadStatus
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [ThreadStatus] -&gt; ShowS
$cshowList :: [ThreadStatus] -&gt; ShowS
show :: ThreadStatus -&gt; String
$cshow :: ThreadStatus -&gt; String
showsPrec :: Int -&gt; ThreadStatus -&gt; ShowS
$cshowsPrec :: Int -&gt; ThreadStatus -&gt; ShowS
</span><a href="GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-568"></span><span>           </span><span class="hs-special">)</span><span>
</span><span id="line-569"></span><span>
</span><span id="line-570"></span><span class="annot"><a href="GHC.Conc.Sync.html#threadStatus"><span class="hs-identifier hs-type">threadStatus</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadStatus"><span class="hs-identifier hs-type">ThreadStatus</span></a></span><span>
</span><span id="line-571"></span><span id="threadStatus"><span class="annot"><span class="annottext">threadStatus :: ThreadId -&gt; IO ThreadStatus
</span><a href="GHC.Conc.Sync.html#threadStatus"><span class="hs-identifier hs-var hs-var">threadStatus</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539579"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539579"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, ThreadStatus #))
-&gt; IO ThreadStatus
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, ThreadStatus #))
 -&gt; IO ThreadStatus)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, ThreadStatus #))
-&gt; IO ThreadStatus
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539578"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539578"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-572"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadId#
-&gt; State# RealWorld -&gt; (# State# RealWorld, Int#, Int#, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#threadStatus%23"><span class="hs-identifier hs-var">threadStatus#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539579"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539578"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-573"></span><span>    </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539577"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539577"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539576"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539576"><span class="hs-identifier hs-var">stat</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539575"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539575"><span class="hs-identifier hs-var">_cap</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539574"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539574"><span class="hs-identifier hs-var">_locked</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539577"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; ThreadStatus
forall {a}. (Eq a, Num a) =&gt; a -&gt; ThreadStatus
</span><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539576"><span class="hs-identifier hs-var">stat</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-574"></span><span>   </span><span class="hs-keyword">where</span><span>
</span><span id="line-575"></span><span>        </span><span class="hs-comment">-- NB. keep these in sync with includes/rts/Constants.h</span><span>
</span><span id="line-576"></span><span>     </span><span id="local-6989586621679539573"><span class="annot"><span class="annottext">mk_stat :: a -&gt; ThreadStatus
</span><a href="#local-6989586621679539573"><span class="hs-identifier hs-var hs-var">mk_stat</span></a></span></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadRunning"><span class="hs-identifier hs-var">ThreadRunning</span></a></span><span>
</span><span id="line-577"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">1</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnMVar"><span class="hs-identifier hs-var">BlockedOnMVar</span></a></span><span>
</span><span id="line-578"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">2</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnBlackHole"><span class="hs-identifier hs-var">BlockedOnBlackHole</span></a></span><span>
</span><span id="line-579"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">6</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnSTM"><span class="hs-identifier hs-var">BlockedOnSTM</span></a></span><span>
</span><span id="line-580"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">10</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnForeignCall"><span class="hs-identifier hs-var">BlockedOnForeignCall</span></a></span><span>
</span><span id="line-581"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">11</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnForeignCall"><span class="hs-identifier hs-var">BlockedOnForeignCall</span></a></span><span>
</span><span id="line-582"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">12</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnException"><span class="hs-identifier hs-var">BlockedOnException</span></a></span><span>
</span><span id="line-583"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">14</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnMVar"><span class="hs-identifier hs-var">BlockedOnMVar</span></a></span><span> </span><span class="hs-comment">-- possibly: BlockedOnMVarRead</span><span>
</span><span id="line-584"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">15</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnIOCompletion"><span class="hs-identifier hs-var">BlockedOnIOCompletion</span></a></span><span>
</span><span id="line-585"></span><span>     </span><span class="hs-comment">-- NB. these are hardcoded in rts/PrimOps.cmm</span><span>
</span><span id="line-586"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">16</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadFinished"><span class="hs-identifier hs-var">ThreadFinished</span></a></span><span>
</span><span id="line-587"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">17</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadDied"><span class="hs-identifier hs-var">ThreadDied</span></a></span><span>
</span><span id="line-588"></span><span>     </span><span class="annot"><a href="#local-6989586621679539573"><span class="hs-identifier hs-var">mk_stat</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BlockReason -&gt; ThreadStatus
</span><a href="GHC.Conc.Sync.html#ThreadBlocked"><span class="hs-identifier hs-var">ThreadBlocked</span></a></span><span> </span><span class="annot"><span class="annottext">BlockReason
</span><a href="GHC.Conc.Sync.html#BlockedOnOther"><span class="hs-identifier hs-var">BlockedOnOther</span></a></span><span>
</span><span id="line-589"></span><span>
</span><span id="line-590"></span><span class="hs-comment">-- | Returns the number of the capability on which the thread is currently</span><span>
</span><span id="line-591"></span><span class="hs-comment">-- running, and a boolean indicating whether the thread is locked to</span><span>
</span><span id="line-592"></span><span class="hs-comment">-- that capability or not.  A thread is locked to a capability if it</span><span>
</span><span id="line-593"></span><span class="hs-comment">-- was created with @forkOn@.</span><span>
</span><span id="line-594"></span><span class="hs-comment">--</span><span>
</span><span id="line-595"></span><span class="hs-comment">-- @since 4.4.0.0</span><span>
</span><span id="line-596"></span><span class="annot"><a href="GHC.Conc.Sync.html#threadCapability"><span class="hs-identifier hs-type">threadCapability</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-597"></span><span id="threadCapability"><span class="annot"><span class="annottext">threadCapability :: ThreadId -&gt; IO (Int, Bool)
</span><a href="GHC.Conc.Sync.html#threadCapability"><span class="hs-identifier hs-var hs-var">threadCapability</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539548"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539548"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, (Int, Bool) #))
-&gt; IO (Int, Bool)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, (Int, Bool) #))
 -&gt; IO (Int, Bool))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, (Int, Bool) #))
-&gt; IO (Int, Bool)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539547"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539547"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-598"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadId#
-&gt; State# RealWorld -&gt; (# State# RealWorld, Int#, Int#, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#threadStatus%23"><span class="hs-identifier hs-var">threadStatus#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539548"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539547"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-599"></span><span>     </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539546"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539546"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539545"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539545"><span class="hs-identifier hs-var">cap#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539544"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539544"><span class="hs-identifier hs-var">locked#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539546"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int# -&gt; Int
</span><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-var">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539545"><span class="hs-identifier hs-var">cap#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#isTrue%23"><span class="hs-identifier hs-var">isTrue#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679539544"><span class="hs-identifier hs-var">locked#</span></a></span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Int# -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#%2F%3D%23"><span class="hs-operator hs-var">/=#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-number">0#</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-600"></span><span>
</span><span id="line-601"></span><span class="hs-comment">-- | Make a weak pointer to a 'ThreadId'.  It can be important to do</span><span>
</span><span id="line-602"></span><span class="hs-comment">-- this if you want to hold a reference to a 'ThreadId' while still</span><span>
</span><span id="line-603"></span><span class="hs-comment">-- allowing the thread to receive the @BlockedIndefinitely@ family of</span><span>
</span><span id="line-604"></span><span class="hs-comment">-- exceptions (e.g. 'BlockedIndefinitelyOnMVar').  Holding a normal</span><span>
</span><span id="line-605"></span><span class="hs-comment">-- 'ThreadId' reference will prevent the delivery of</span><span>
</span><span id="line-606"></span><span class="hs-comment">-- @BlockedIndefinitely@ exceptions because the reference could be</span><span>
</span><span id="line-607"></span><span class="hs-comment">-- used as the target of 'throwTo' at any time, which would unblock</span><span>
</span><span id="line-608"></span><span class="hs-comment">-- the thread.</span><span>
</span><span id="line-609"></span><span class="hs-comment">--</span><span>
</span><span id="line-610"></span><span class="hs-comment">-- Holding a @Weak ThreadId@, on the other hand, will not prevent the</span><span>
</span><span id="line-611"></span><span class="hs-comment">-- thread from receiving @BlockedIndefinitely@ exceptions.  It is</span><span>
</span><span id="line-612"></span><span class="hs-comment">-- still possible to throw an exception to a @Weak ThreadId@, but the</span><span>
</span><span id="line-613"></span><span class="hs-comment">-- caller must use @deRefWeak@ first to determine whether the thread</span><span>
</span><span id="line-614"></span><span class="hs-comment">-- still exists.</span><span>
</span><span id="line-615"></span><span class="hs-comment">--</span><span>
</span><span id="line-616"></span><span class="hs-comment">-- @since 4.6.0.0</span><span>
</span><span id="line-617"></span><span class="annot"><a href="GHC.Conc.Sync.html#mkWeakThreadId"><span class="hs-identifier hs-type">mkWeakThreadId</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Weak.html#Weak"><span class="hs-identifier hs-type">Weak</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-618"></span><span id="mkWeakThreadId"><span class="annot"><span class="annottext">mkWeakThreadId :: ThreadId -&gt; IO (Weak ThreadId)
</span><a href="GHC.Conc.Sync.html#mkWeakThreadId"><span class="hs-identifier hs-var hs-var">mkWeakThreadId</span></a></span></span><span> </span><span id="local-6989586621679539543"><span class="annot"><span class="annottext">t :: ThreadId
</span><a href="#local-6989586621679539543"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539542"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539542"><span class="hs-identifier hs-var">t#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, Weak ThreadId #))
-&gt; IO (Weak ThreadId)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, Weak ThreadId #))
 -&gt; IO (Weak ThreadId))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, Weak ThreadId #))
-&gt; IO (Weak ThreadId)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539541"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539541"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-619"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ThreadId#
-&gt; ThreadId
-&gt; State# RealWorld
-&gt; (# State# RealWorld, Weak# ThreadId #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#mkWeakNoFinalizer%23"><span class="hs-identifier hs-var">mkWeakNoFinalizer#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539542"><span class="hs-identifier hs-var">t#</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679539543"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539541"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-620"></span><span>      </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539540"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539540"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539539"><span class="annot"><span class="annottext">Weak# ThreadId
</span><a href="#local-6989586621679539539"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539540"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Weak# ThreadId -&gt; Weak ThreadId
forall v. Weak# v -&gt; Weak v
</span><a href="GHC.Weak.html#Weak"><span class="hs-identifier hs-var">Weak</span></a></span><span> </span><span class="annot"><span class="annottext">Weak# ThreadId
</span><a href="#local-6989586621679539539"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-621"></span><span>
</span><span id="line-622"></span><span>
</span><span id="line-623"></span><span class="hs-keyword">data</span><span> </span><span id="PrimMVar"><span class="annot"><a href="GHC.Conc.Sync.html#PrimMVar"><span class="hs-identifier hs-var">PrimMVar</span></a></span></span><span>
</span><span id="line-624"></span><span>
</span><span id="line-625"></span><span class="hs-comment">-- | Make a StablePtr that can be passed to the C function</span><span>
</span><span id="line-626"></span><span class="hs-comment">-- @hs_try_putmvar()@.  The RTS wants a 'StablePtr' to the underlying</span><span>
</span><span id="line-627"></span><span class="hs-comment">-- 'MVar#', but a 'StablePtr#' can only refer to lifted types, so we</span><span>
</span><span id="line-628"></span><span class="hs-comment">-- have to cheat by coercing.</span><span>
</span><span id="line-629"></span><span class="annot"><a href="GHC.Conc.Sync.html#newStablePtrPrimMVar"><span class="hs-identifier hs-type">newStablePtrPrimMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stable.html#StablePtr"><span class="hs-identifier hs-type">StablePtr</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#PrimMVar"><span class="hs-identifier hs-type">PrimMVar</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-630"></span><span id="newStablePtrPrimMVar"><span class="annot"><span class="annottext">newStablePtrPrimMVar :: MVar () -&gt; IO (StablePtr PrimMVar)
</span><a href="GHC.Conc.Sync.html#newStablePtrPrimMVar"><span class="hs-identifier hs-var hs-var">newStablePtrPrimMVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span id="local-6989586621679539536"><span class="annot"><span class="annottext">MVar# RealWorld ()
</span><a href="#local-6989586621679539536"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, StablePtr PrimMVar #))
-&gt; IO (StablePtr PrimMVar)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, StablePtr PrimMVar #))
 -&gt; IO (StablePtr PrimMVar))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, StablePtr PrimMVar #))
-&gt; IO (StablePtr PrimMVar)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539535"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539535"><span class="hs-identifier hs-var">s0</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-631"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">PrimMVar
-&gt; State# RealWorld -&gt; (# State# RealWorld, StablePtr# PrimMVar #)
forall a.
a -&gt; State# RealWorld -&gt; (# State# RealWorld, StablePtr# a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#makeStablePtr%23"><span class="hs-identifier hs-var">makeStablePtr#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MVar# RealWorld () -&gt; PrimMVar
forall a b. a -&gt; b
</span><a href="Unsafe.Coerce.html#unsafeCoerce%23"><span class="hs-identifier hs-var">unsafeCoerce#</span></a></span><span> </span><span class="annot"><span class="annottext">MVar# RealWorld ()
</span><a href="#local-6989586621679539536"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#PrimMVar"><span class="hs-identifier hs-type">PrimMVar</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539535"><span class="hs-identifier hs-var">s0</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-632"></span><span>    </span><span class="hs-comment">-- Coerce unlifted  m :: MVar# RealWorld ()</span><span>
</span><span id="line-633"></span><span>    </span><span class="hs-comment">--     to lifted    PrimMVar</span><span>
</span><span id="line-634"></span><span>    </span><span class="hs-comment">-- apparently because mkStablePtr is not levity-polymorphic</span><span>
</span><span id="line-635"></span><span>    </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539534"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539534"><span class="hs-identifier hs-var">s1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539533"><span class="annot"><span class="annottext">StablePtr# PrimMVar
</span><a href="#local-6989586621679539533"><span class="hs-identifier hs-var">sp</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539534"><span class="hs-identifier hs-var">s1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">StablePtr# PrimMVar -&gt; StablePtr PrimMVar
forall a. StablePtr# a -&gt; StablePtr a
</span><a href="GHC.Stable.html#StablePtr"><span class="hs-identifier hs-var">StablePtr</span></a></span><span> </span><span class="annot"><span class="annottext">StablePtr# PrimMVar
</span><a href="#local-6989586621679539533"><span class="hs-identifier hs-var">sp</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-636"></span><span>
</span><span id="line-637"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-638"></span><span class="hs-comment">-- Transactional heap operations</span><span>
</span><span id="line-639"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-640"></span><span>
</span><span id="line-641"></span><span class="hs-comment">-- TVars are shared memory locations which support atomic memory</span><span>
</span><span id="line-642"></span><span class="hs-comment">-- transactions.</span><span>
</span><span id="line-643"></span><span>
</span><span id="line-644"></span><span class="hs-comment">-- |A monad supporting atomic memory transactions.</span><span>
</span><span id="line-645"></span><span class="hs-keyword">newtype</span><span> </span><span id="STM"><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span></span><span> </span><span id="local-6989586621679540013"><span class="annot"><a href="#local-6989586621679540013"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="STM"><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#State%23"><span class="hs-identifier hs-type">State#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#State%23"><span class="hs-identifier hs-type">State#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679540013"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">#)</span><span class="hs-special">)</span><span>
</span><span id="line-646"></span><span>
</span><span id="line-647"></span><span id="local-6989586621679540055"><span class="annot"><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-type">unSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540055"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#State%23"><span class="hs-identifier hs-type">State#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#State%23"><span class="hs-identifier hs-type">State#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679540055"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">#)</span><span class="hs-special">)</span></span><span>
</span><span id="line-648"></span><span id="unSTM"><span class="annot"><span class="annottext">unSTM :: forall a. STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-var hs-var">unSTM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539529"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539529"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539529"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-649"></span><span>
</span><span id="line-650"></span><span class="hs-comment">-- | @since 4.3.0.0</span><span>
</span><span id="line-651"></span><span class="hs-keyword">instance</span><span>  </span><span id="local-6989586621679539526"><span class="annot"><a href="GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-652"></span><span>   </span><span id="local-6989586621679539522"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; STM a -&gt; STM b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span id="local-6989586621679539521"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679539521"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679539520"><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539520"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539520"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">STM a -&gt; (a -&gt; STM b) -&gt; STM b
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; STM b
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(b -&gt; STM b) -&gt; (a -&gt; b) -&gt; a -&gt; STM b
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679539521"><span class="hs-identifier hs-var">f</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-653"></span><span>
</span><span id="line-654"></span><span class="hs-comment">-- | @since 4.8.0.0</span><span>
</span><span id="line-655"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539512"><span class="annot"><a href="GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-656"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Base.html#pure"><span class="hs-pragma hs-type">pure</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-657"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">*&gt;</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-658"></span><span>  </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Base.html#liftA2"><span class="hs-pragma hs-type">liftA2</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-659"></span><span>  </span><span id="local-6989586621679539509"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; STM a
</span><a href="GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679539508"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539508"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall a. a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#returnSTM"><span class="hs-identifier hs-var">returnSTM</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539508"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-660"></span><span>  </span><span id="local-6989586621679539505"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. STM (a -&gt; b) -&gt; STM a -&gt; STM b
</span><a href="GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM (a -&gt; b) -&gt; STM a -&gt; STM b
forall (m :: * -&gt; *) a b. Monad m =&gt; m (a -&gt; b) -&gt; m a -&gt; m b
</span><a href="GHC.Base.html#ap"><span class="hs-identifier hs-var">ap</span></a></span><span>
</span><span id="line-661"></span><span>  </span><span id="local-6989586621679539502"><span class="annot"><span class="annottext">liftA2 :: forall a b c. (a -&gt; b -&gt; c) -&gt; STM a -&gt; STM b -&gt; STM c
</span><a href="#local-6989586621679539502"><span class="hs-identifier hs-var hs-var hs-var hs-var">liftA2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b -&gt; c) -&gt; STM a -&gt; STM b -&gt; STM c
forall (m :: * -&gt; *) a1 a2 r.
Monad m =&gt;
(a1 -&gt; a2 -&gt; r) -&gt; m a1 -&gt; m a2 -&gt; m r
</span><a href="GHC.Base.html#liftM2"><span class="hs-identifier hs-var">liftM2</span></a></span><span>
</span><span id="line-662"></span><span>  </span><span id="local-6989586621679539500"><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539500"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679539499"><span class="annot"><span class="annottext">*&gt; :: forall a b. STM a -&gt; STM b -&gt; STM b
</span><a href="GHC.Base.html#%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">*&gt;</span></a></span></span><span> </span><span id="local-6989586621679539498"><span class="annot"><span class="annottext">STM b
</span><a href="#local-6989586621679539498"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a -&gt; STM b -&gt; STM b
forall a b. STM a -&gt; STM b -&gt; STM b
</span><a href="GHC.Conc.Sync.html#thenSTM"><span class="hs-identifier hs-var">thenSTM</span></a></span><span> </span><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539500"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">STM b
</span><a href="#local-6989586621679539498"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-663"></span><span>
</span><span id="line-664"></span><span class="hs-comment">-- | @since 4.3.0.0</span><span>
</span><span id="line-665"></span><span class="hs-keyword">instance</span><span>  </span><span id="local-6989586621679539491"><span class="annot"><a href="GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-666"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&gt;&gt;=</span><span class="hs-pragma">)</span><span>  </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-667"></span><span>    </span><span id="local-6989586621679539489"><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539489"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679539488"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. STM a -&gt; (a -&gt; STM b) -&gt; STM b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621679539487"><span class="annot"><span class="annottext">a -&gt; STM b
</span><a href="#local-6989586621679539487"><span class="hs-identifier hs-var">k</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a -&gt; (a -&gt; STM b) -&gt; STM b
forall a b. STM a -&gt; (a -&gt; STM b) -&gt; STM b
</span><a href="GHC.Conc.Sync.html#bindSTM"><span class="hs-identifier hs-var">bindSTM</span></a></span><span> </span><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539489"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; STM b
</span><a href="#local-6989586621679539487"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-668"></span><span>    </span><span id="local-6989586621679539484"><span class="annot"><span class="annottext">&gt;&gt; :: forall a b. STM a -&gt; STM b -&gt; STM b
</span><a href="GHC.Base.html#%3E%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&gt;&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a -&gt; STM b -&gt; STM b
forall (f :: * -&gt; *) a b. Applicative f =&gt; f a -&gt; f b -&gt; f b
</span><a href="GHC.Base.html#%2A%3E"><span class="hs-operator hs-var">(*&gt;)</span></a></span><span>
</span><span id="line-669"></span><span>
</span><span id="line-670"></span><span id="local-6989586621679539482"><span id="local-6989586621679539483"><span class="annot"><a href="GHC.Conc.Sync.html#bindSTM"><span class="hs-identifier hs-type">bindSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539483"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679539483"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539482"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539482"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-671"></span><span id="bindSTM"><span class="annot"><span class="annottext">bindSTM :: forall a b. STM a -&gt; (a -&gt; STM b) -&gt; STM b
</span><a href="GHC.Conc.Sync.html#bindSTM"><span class="hs-identifier hs-var hs-var">bindSTM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539481"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539481"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539480"><span class="annot"><span class="annottext">a -&gt; STM b
</span><a href="#local-6989586621679539480"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; STM b
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539479"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539479"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-672"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539481"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539479"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-673"></span><span>    </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539478"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539478"><span class="hs-identifier hs-var">new_s</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539477"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539477"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM b -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
forall a. STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-var">unSTM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; STM b
</span><a href="#local-6989586621679539480"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539477"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539478"><span class="hs-identifier hs-var">new_s</span></a></span><span>
</span><span id="line-674"></span><span>  </span><span class="hs-special">)</span><span>
</span><span id="line-675"></span><span>
</span><span id="line-676"></span><span id="local-6989586621679539475"><span id="local-6989586621679539476"><span class="annot"><a href="GHC.Conc.Sync.html#thenSTM"><span class="hs-identifier hs-type">thenSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539476"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539475"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539475"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-677"></span><span id="thenSTM"><span class="annot"><span class="annottext">thenSTM :: forall a b. STM a -&gt; STM b -&gt; STM b
</span><a href="GHC.Conc.Sync.html#thenSTM"><span class="hs-identifier hs-var hs-var">thenSTM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539474"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539474"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539473"><span class="annot"><span class="annottext">STM b
</span><a href="#local-6989586621679539473"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, b #)) -&gt; STM b
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539472"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539472"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-678"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539474"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539472"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-679"></span><span>    </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539471"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539471"><span class="hs-identifier hs-var">new_s</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM b -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
forall a. STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-var">unSTM</span></a></span><span> </span><span class="annot"><span class="annottext">STM b
</span><a href="#local-6989586621679539473"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539471"><span class="hs-identifier hs-var">new_s</span></a></span><span>
</span><span id="line-680"></span><span>  </span><span class="hs-special">)</span><span>
</span><span id="line-681"></span><span>
</span><span id="line-682"></span><span id="local-6989586621679539470"><span class="annot"><a href="GHC.Conc.Sync.html#returnSTM"><span class="hs-identifier hs-type">returnSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679539470"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539470"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-683"></span><span id="returnSTM"><span class="annot"><span class="annottext">returnSTM :: forall a. a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#returnSTM"><span class="hs-identifier hs-var hs-var">returnSTM</span></a></span></span><span> </span><span id="local-6989586621679539469"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539469"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679539468"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539468"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539468"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539469"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">#)</span><span class="hs-special">)</span><span>
</span><span id="line-684"></span><span>
</span><span id="line-685"></span><span class="hs-comment">-- | @since 4.8.0.0</span><span>
</span><span id="line-686"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539460"><span id="local-6989586621679539462"><span class="annot"><a href="GHC.Base.html#Alternative"><span class="hs-identifier hs-type">Alternative</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-687"></span><span>  </span><span id="local-6989586621679539458"><span class="annot"><span class="annottext">empty :: forall a. STM a
</span><a href="GHC.Base.html#empty"><span class="hs-identifier hs-var hs-var hs-var hs-var">empty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-688"></span><span>  </span><span id="local-6989586621679539456"><span class="annot"><span class="annottext">&lt;|&gt; :: forall a. STM a -&gt; STM a -&gt; STM a
</span><a href="GHC.Base.html#%3C%7C%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;|&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STM a -&gt; STM a -&gt; STM a
forall a. STM a -&gt; STM a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#orElse"><span class="hs-identifier hs-var">orElse</span></a></span><span>
</span><span id="line-689"></span><span>
</span><span id="line-690"></span><span class="hs-comment">-- | @since 4.3.0.0</span><span>
</span><span id="line-691"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539447"><span id="local-6989586621679539449"><span class="annot"><a href="GHC.Base.html#MonadPlus"><span class="hs-identifier hs-type">MonadPlus</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span></span></span><span>
</span><span id="line-692"></span><span>
</span><span id="line-693"></span><span class="hs-comment">-- | Unsafely performs IO in the STM monad.  Beware: this is a highly</span><span>
</span><span id="line-694"></span><span class="hs-comment">-- dangerous thing to do.</span><span>
</span><span id="line-695"></span><span class="hs-comment">--</span><span>
</span><span id="line-696"></span><span class="hs-comment">--   * The STM implementation will often run transactions multiple</span><span>
</span><span id="line-697"></span><span class="hs-comment">--     times, so you need to be prepared for this if your IO has any</span><span>
</span><span id="line-698"></span><span class="hs-comment">--     side effects.</span><span>
</span><span id="line-699"></span><span class="hs-comment">--</span><span>
</span><span id="line-700"></span><span class="hs-comment">--   * The STM implementation will abort transactions that are known to</span><span>
</span><span id="line-701"></span><span class="hs-comment">--     be invalid and need to be restarted.  This may happen in the middle</span><span>
</span><span id="line-702"></span><span class="hs-comment">--     of `unsafeIOToSTM`, so make sure you don't acquire any resources</span><span>
</span><span id="line-703"></span><span class="hs-comment">--     that need releasing (exception handlers are ignored when aborting</span><span>
</span><span id="line-704"></span><span class="hs-comment">--     the transaction).  That includes doing any IO using Handles, for</span><span>
</span><span id="line-705"></span><span class="hs-comment">--     example.  Getting this wrong will probably lead to random deadlocks.</span><span>
</span><span id="line-706"></span><span class="hs-comment">--</span><span>
</span><span id="line-707"></span><span class="hs-comment">--   * The transaction may have seen an inconsistent view of memory when</span><span>
</span><span id="line-708"></span><span class="hs-comment">--     the IO runs.  Invariants that you expect to be true throughout</span><span>
</span><span id="line-709"></span><span class="hs-comment">--     your program may not be true inside a transaction, due to the</span><span>
</span><span id="line-710"></span><span class="hs-comment">--     way transactions are implemented.  Normally this wouldn't be visible</span><span>
</span><span id="line-711"></span><span class="hs-comment">--     to the programmer, but using `unsafeIOToSTM` can expose it.</span><span>
</span><span id="line-712"></span><span class="hs-comment">--</span><span>
</span><span id="line-713"></span><span id="local-6989586621679540000"><span class="annot"><a href="GHC.Conc.Sync.html#unsafeIOToSTM"><span class="hs-identifier hs-type">unsafeIOToSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540000"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679540000"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-714"></span><span id="unsafeIOToSTM"><span class="annot"><span class="annottext">unsafeIOToSTM :: forall a. IO a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#unsafeIOToSTM"><span class="hs-identifier hs-var hs-var">unsafeIOToSTM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679539445"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539445"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539445"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-715"></span><span>
</span><span id="line-716"></span><span class="hs-comment">-- | Perform a series of STM actions atomically.</span><span>
</span><span id="line-717"></span><span class="hs-comment">--</span><span>
</span><span id="line-718"></span><span class="hs-comment">-- Using 'atomically' inside an 'unsafePerformIO' or 'unsafeInterleaveIO'</span><span>
</span><span id="line-719"></span><span class="hs-comment">-- subverts some of guarantees that STM provides. It makes it possible to</span><span>
</span><span id="line-720"></span><span class="hs-comment">-- run a transaction inside of another transaction, depending on when the</span><span>
</span><span id="line-721"></span><span class="hs-comment">-- thunk is evaluated. If a nested transaction is attempted, an exception</span><span>
</span><span id="line-722"></span><span class="hs-comment">-- is thrown by the runtime. It is possible to safely use 'atomically' inside</span><span>
</span><span id="line-723"></span><span class="hs-comment">-- 'unsafePerformIO' or 'unsafeInterleaveIO', but the typechecker does not</span><span>
</span><span id="line-724"></span><span class="hs-comment">-- rule out programs that may attempt nested transactions, meaning that</span><span>
</span><span id="line-725"></span><span class="hs-comment">-- the programmer must take special care to prevent these.</span><span>
</span><span id="line-726"></span><span class="hs-comment">--</span><span>
</span><span id="line-727"></span><span class="hs-comment">-- However, there are functions for creating transactional variables that</span><span>
</span><span id="line-728"></span><span class="hs-comment">-- can always be safely called in 'unsafePerformIO'. See: 'newTVarIO',</span><span>
</span><span id="line-729"></span><span class="hs-comment">-- 'Control.Concurrent.STM.TChan.newTChanIO',</span><span>
</span><span id="line-730"></span><span class="hs-comment">-- 'Control.Concurrent.STM.TChan.newBroadcastTChanIO',</span><span>
</span><span id="line-731"></span><span class="hs-comment">-- 'Control.Concurrent.STM.TQueue.newTQueueIO',</span><span>
</span><span id="line-732"></span><span class="hs-comment">-- 'Control.Concurrent.STM.TBQueue.newTBQueueIO', and</span><span>
</span><span id="line-733"></span><span class="hs-comment">-- 'Control.Concurrent.STM.TMVar.newTMVarIO'.</span><span>
</span><span id="line-734"></span><span class="hs-comment">--</span><span>
</span><span id="line-735"></span><span class="hs-comment">-- Using 'unsafePerformIO' inside of 'atomically' is also dangerous but for</span><span>
</span><span id="line-736"></span><span class="hs-comment">-- different reasons. See 'unsafeIOToSTM' for more on this.</span><span>
</span><span id="line-737"></span><span>
</span><span id="line-738"></span><span id="local-6989586621679539998"><span class="annot"><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-type">atomically</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539998"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539998"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-739"></span><span id="atomically"><span class="annot"><span class="annottext">atomically :: forall a. STM a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-var hs-var">atomically</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539444"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539444"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679539443"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539443"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#atomically%23"><span class="hs-identifier hs-var">atomically#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539444"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539443"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-740"></span><span>
</span><span id="line-741"></span><span class="hs-comment">-- | Retry execution of the current memory transaction because it has seen</span><span>
</span><span id="line-742"></span><span class="hs-comment">-- values in 'TVar's which mean that it should not continue (e.g. the 'TVar's</span><span>
</span><span id="line-743"></span><span class="hs-comment">-- represent a shared buffer that is now empty).  The implementation may</span><span>
</span><span id="line-744"></span><span class="hs-comment">-- block the thread until one of the 'TVar's that it has read from has been</span><span>
</span><span id="line-745"></span><span class="hs-comment">-- updated. (GHC only)</span><span>
</span><span id="line-746"></span><span id="local-6989586621679539442"><span class="annot"><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-type">retry</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539442"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-747"></span><span id="retry"><span class="annot"><span class="annottext">retry :: forall a. STM a
</span><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var hs-var">retry</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539441"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539441"><span class="hs-identifier hs-var">s#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
forall a. State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#retry%23"><span class="hs-identifier hs-var">retry#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539441"><span class="hs-identifier hs-var">s#</span></a></span><span>
</span><span id="line-748"></span><span>
</span><span id="line-749"></span><span class="hs-comment">-- | Compose two alternative STM actions (GHC only).</span><span>
</span><span id="line-750"></span><span class="hs-comment">--</span><span>
</span><span id="line-751"></span><span class="hs-comment">-- If the first action completes without retrying then it forms the result of</span><span>
</span><span id="line-752"></span><span class="hs-comment">-- the 'orElse'. Otherwise, if the first action retries, then the second action</span><span>
</span><span id="line-753"></span><span class="hs-comment">-- is tried in its place. If both actions retry then the 'orElse' as a whole</span><span>
</span><span id="line-754"></span><span class="hs-comment">-- retries.</span><span>
</span><span id="line-755"></span><span id="local-6989586621679539440"><span class="annot"><a href="GHC.Conc.Sync.html#orElse"><span class="hs-identifier hs-type">orElse</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539440"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539440"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539440"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-756"></span><span id="orElse"><span class="annot"><span class="annottext">orElse :: forall a. STM a -&gt; STM a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#orElse"><span class="hs-identifier hs-var hs-var">orElse</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539439"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539439"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539438"><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539438"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539437"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539437"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
forall a.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#catchRetry%23"><span class="hs-identifier hs-var">catchRetry#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539439"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a. STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-var">unSTM</span></a></span><span> </span><span class="annot"><span class="annottext">STM a
</span><a href="#local-6989586621679539438"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539437"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-757"></span><span>
</span><span id="line-758"></span><span class="hs-comment">-- | A variant of 'throw' that can only be used within the 'STM' monad.</span><span>
</span><span id="line-759"></span><span class="hs-comment">--</span><span>
</span><span id="line-760"></span><span class="hs-comment">-- Throwing an exception in @STM@ aborts the transaction and propagates the</span><span>
</span><span id="line-761"></span><span class="hs-comment">-- exception. If the exception is caught via 'catchSTM', only the changes</span><span>
</span><span id="line-762"></span><span class="hs-comment">-- enclosed by the catch are rolled back; changes made outside of 'catchSTM'</span><span>
</span><span id="line-763"></span><span class="hs-comment">-- persist.</span><span>
</span><span id="line-764"></span><span class="hs-comment">--</span><span>
</span><span id="line-765"></span><span class="hs-comment">-- If the exception is not caught inside of the 'STM', it is re-thrown by</span><span>
</span><span id="line-766"></span><span class="hs-comment">-- 'atomically', and the entire 'STM' is rolled back.</span><span>
</span><span id="line-767"></span><span class="hs-comment">--</span><span>
</span><span id="line-768"></span><span class="hs-comment">-- Although 'throwSTM' has a type that is an instance of the type of 'throw', the</span><span>
</span><span id="line-769"></span><span class="hs-comment">-- two functions are subtly different:</span><span>
</span><span id="line-770"></span><span class="hs-comment">--</span><span>
</span><span id="line-771"></span><span class="hs-comment">-- &gt; throw e    `seq` x  ===&gt; throw e</span><span>
</span><span id="line-772"></span><span class="hs-comment">-- &gt; throwSTM e `seq` x  ===&gt; x</span><span>
</span><span id="line-773"></span><span class="hs-comment">--</span><span>
</span><span id="line-774"></span><span class="hs-comment">-- The first example will cause the exception @e@ to be raised,</span><span>
</span><span id="line-775"></span><span class="hs-comment">-- whereas the second one won\'t.  In fact, 'throwSTM' will only cause</span><span>
</span><span id="line-776"></span><span class="hs-comment">-- an exception to be raised when it is used within the 'STM' monad.</span><span>
</span><span id="line-777"></span><span class="hs-comment">-- The 'throwSTM' variant should be used in preference to 'throw' to</span><span>
</span><span id="line-778"></span><span class="hs-comment">-- raise an exception within the 'STM' monad because it guarantees</span><span>
</span><span id="line-779"></span><span class="hs-comment">-- ordering with respect to other 'STM' operations, whereas 'throw'</span><span>
</span><span id="line-780"></span><span class="hs-comment">-- does not.</span><span>
</span><span id="line-781"></span><span id="local-6989586621679539993"><span id="local-6989586621679539994"><span class="annot"><a href="GHC.Conc.Sync.html#throwSTM"><span class="hs-identifier hs-type">throwSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539994"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679539994"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539993"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-782"></span><span id="throwSTM"><span class="annot"><span class="annottext">throwSTM :: forall e a. Exception e =&gt; e -&gt; STM a
</span><a href="GHC.Conc.Sync.html#throwSTM"><span class="hs-identifier hs-var hs-var">throwSTM</span></a></span></span><span> </span><span id="local-6989586621679539434"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539434"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a b. a -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#raiseIO%23"><span class="hs-identifier hs-var">raiseIO#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; SomeException
forall e. Exception e =&gt; e -&gt; SomeException
</span><a href="GHC.Exception.Type.html#toException"><span class="hs-identifier hs-var">toException</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539434"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-783"></span><span>
</span><span id="line-784"></span><span class="hs-comment">-- | Exception handling within STM actions.</span><span>
</span><span id="line-785"></span><span class="hs-comment">--</span><span>
</span><span id="line-786"></span><span class="hs-comment">-- @'catchSTM' m f@ catches any exception thrown by @m@ using 'throwSTM',</span><span>
</span><span id="line-787"></span><span class="hs-comment">-- using the function @f@ to handle the exception. If an exception is</span><span>
</span><span id="line-788"></span><span class="hs-comment">-- thrown, any changes made by @m@ are rolled back, but changes prior to</span><span>
</span><span id="line-789"></span><span class="hs-comment">-- @m@ persist.</span><span>
</span><span id="line-790"></span><span id="local-6989586621679539989"><span id="local-6989586621679539990"><span class="annot"><a href="GHC.Conc.Sync.html#catchSTM"><span class="hs-identifier hs-type">catchSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539990"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539989"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679539990"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539989"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539989"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-791"></span><span id="catchSTM"><span class="annot"><span class="annottext">catchSTM :: forall e a. Exception e =&gt; STM a -&gt; (e -&gt; STM a) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#catchSTM"><span class="hs-identifier hs-var hs-var">catchSTM</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span id="local-6989586621679539432"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539432"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539431"><span class="annot"><span class="annottext">e -&gt; STM a
</span><a href="#local-6989586621679539431"><span class="hs-identifier hs-var">handler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
forall a b.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (b -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#catchSTM%23"><span class="hs-identifier hs-var">catchSTM#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539432"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539430"><span class="hs-identifier hs-var">handler'</span></a></span><span>
</span><span id="line-792"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-793"></span><span>      </span><span id="local-6989586621679539430"><span class="annot"><span class="annottext">handler' :: SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679539430"><span class="hs-identifier hs-var hs-var">handler'</span></a></span></span><span> </span><span id="local-6989586621679539428"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539428"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe e
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539428"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-794"></span><span>                     </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679539427"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539427"><span class="hs-identifier hs-var">e'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a. STM a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Conc.Sync.html#unSTM"><span class="hs-identifier hs-var">unSTM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; STM a
</span><a href="#local-6989586621679539431"><span class="hs-identifier hs-var">handler</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539427"><span class="hs-identifier hs-var">e'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-795"></span><span>                     </span><span class="annot"><span class="annottext">Maybe e
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a b. a -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#raiseIO%23"><span class="hs-identifier hs-var">raiseIO#</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539428"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-796"></span><span>
</span><span id="line-797"></span><span class="hs-comment">-- |Shared memory locations that support atomic memory transactions.</span><span>
</span><span id="line-798"></span><span class="hs-keyword">data</span><span> </span><span id="TVar"><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-var">TVar</span></a></span></span><span> </span><span id="local-6989586621679539983"><span class="annot"><a href="#local-6989586621679539983"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TVar"><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-var">TVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#TVar%23"><span class="hs-identifier hs-type">TVar#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539983"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-799"></span><span>
</span><span id="line-800"></span><span class="hs-comment">-- | @since 4.8.0.0</span><span>
</span><span id="line-801"></span><span id="local-6989586621679539986"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679539423"><span class="annot"><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-type">Eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539986"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-802"></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679539422"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539422"><span class="hs-identifier hs-var">tvar1#</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539421"><span class="annot"><span class="annottext">== :: TVar a -&gt; TVar a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">==</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679539420"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539420"><span class="hs-identifier hs-var">tvar2#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#isTrue%23"><span class="hs-identifier hs-var">isTrue#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; TVar# RealWorld a -&gt; Int#
forall d a. TVar# d a -&gt; TVar# d a -&gt; Int#
</span><a href="../../ghc-prim/src/GHC.Prim.html#sameTVar%23"><span class="hs-identifier hs-var">sameTVar#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539422"><span class="hs-identifier hs-var">tvar1#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539420"><span class="hs-identifier hs-var">tvar2#</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-803"></span><span>
</span><span id="line-804"></span><span class="hs-comment">-- | Create a new 'TVar' holding a value supplied</span><span>
</span><span id="line-805"></span><span id="local-6989586621679539985"><span class="annot"><a href="GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-type">newTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679539985"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539985"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-806"></span><span id="newTVar"><span class="annot"><span class="annottext">newTVar :: forall a. a -&gt; STM (TVar a)
</span><a href="GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var hs-var">newTVar</span></a></span></span><span> </span><span id="local-6989586621679539419"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539419"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, TVar a #))
-&gt; STM (TVar a)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, TVar a #))
 -&gt; STM (TVar a))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, TVar a #))
-&gt; STM (TVar a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539418"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539418"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-807"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a -&gt; State# RealWorld -&gt; (# State# RealWorld, TVar# RealWorld a #)
forall a d. a -&gt; State# d -&gt; (# State# d, TVar# d a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#newTVar%23"><span class="hs-identifier hs-var">newTVar#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539419"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539418"><span class="hs-identifier hs-var">s1#</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-808"></span><span>         </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539417"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539417"><span class="hs-identifier hs-var">s2#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539416"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539416"><span class="hs-identifier hs-var">tvar#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539417"><span class="hs-identifier hs-var">s2#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; TVar a
forall a. TVar# RealWorld a -&gt; TVar a
</span><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-var">TVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539416"><span class="hs-identifier hs-var">tvar#</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-809"></span><span>
</span><span id="line-810"></span><span class="hs-comment">-- | @IO@ version of 'newTVar'.  This is useful for creating top-level</span><span>
</span><span id="line-811"></span><span class="hs-comment">-- 'TVar's using 'System.IO.Unsafe.unsafePerformIO', because using</span><span>
</span><span id="line-812"></span><span class="hs-comment">-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't</span><span>
</span><span id="line-813"></span><span class="hs-comment">-- possible.</span><span>
</span><span id="line-814"></span><span id="local-6989586621679539982"><span class="annot"><a href="GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-type">newTVarIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679539982"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539982"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-815"></span><span id="newTVarIO"><span class="annot"><span class="annottext">newTVarIO :: forall a. a -&gt; IO (TVar a)
</span><a href="GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var hs-var">newTVarIO</span></a></span></span><span> </span><span id="local-6989586621679539415"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539415"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, TVar a #)) -&gt; IO (TVar a)
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, TVar a #))
 -&gt; IO (TVar a))
-&gt; (State# RealWorld -&gt; (# State# RealWorld, TVar a #))
-&gt; IO (TVar a)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539414"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539414"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-816"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a -&gt; State# RealWorld -&gt; (# State# RealWorld, TVar# RealWorld a #)
forall a d. a -&gt; State# d -&gt; (# State# d, TVar# d a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#newTVar%23"><span class="hs-identifier hs-var">newTVar#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539415"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539414"><span class="hs-identifier hs-var">s1#</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-817"></span><span>         </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679539413"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539413"><span class="hs-identifier hs-var">s2#</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679539412"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539412"><span class="hs-identifier hs-var">tvar#</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539413"><span class="hs-identifier hs-var">s2#</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; TVar a
forall a. TVar# RealWorld a -&gt; TVar a
</span><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-var">TVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539412"><span class="hs-identifier hs-var">tvar#</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-818"></span><span>
</span><span id="line-819"></span><span class="hs-comment">-- | Return the current value stored in a 'TVar'.</span><span>
</span><span id="line-820"></span><span class="hs-comment">-- This is equivalent to</span><span>
</span><span id="line-821"></span><span class="hs-comment">--</span><span>
</span><span id="line-822"></span><span class="hs-comment">-- &gt;  readTVarIO = atomically . readTVar</span><span>
</span><span id="line-823"></span><span class="hs-comment">--</span><span>
</span><span id="line-824"></span><span class="hs-comment">-- but works much faster, because it doesn't perform a complete</span><span>
</span><span id="line-825"></span><span class="hs-comment">-- transaction, it just reads the current value of the 'TVar'.</span><span>
</span><span id="line-826"></span><span id="local-6989586621679539980"><span class="annot"><a href="GHC.Conc.Sync.html#readTVarIO"><span class="hs-identifier hs-type">readTVarIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539980"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539980"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-827"></span><span id="readTVarIO"><span class="annot"><span class="annottext">readTVarIO :: forall a. TVar a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#readTVarIO"><span class="hs-identifier hs-var hs-var">readTVarIO</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679539411"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539411"><span class="hs-identifier hs-var">tvar#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539410"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539410"><span class="hs-identifier hs-var">s#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall d a. TVar# d a -&gt; State# d -&gt; (# State# d, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#readTVarIO%23"><span class="hs-identifier hs-var">readTVarIO#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539411"><span class="hs-identifier hs-var">tvar#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539410"><span class="hs-identifier hs-var">s#</span></a></span><span>
</span><span id="line-828"></span><span>
</span><span id="line-829"></span><span class="hs-comment">-- |Return the current value stored in a 'TVar'.</span><span>
</span><span id="line-830"></span><span id="local-6989586621679539978"><span class="annot"><a href="GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-type">readTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539978"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539978"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-831"></span><span id="readTVar"><span class="annot"><span class="annottext">readTVar :: forall a. TVar a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var hs-var">readTVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679539409"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539409"><span class="hs-identifier hs-var">tvar#</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539408"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539408"><span class="hs-identifier hs-var">s#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall d a. TVar# d a -&gt; State# d -&gt; (# State# d, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#readTVar%23"><span class="hs-identifier hs-var">readTVar#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539409"><span class="hs-identifier hs-var">tvar#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539408"><span class="hs-identifier hs-var">s#</span></a></span><span>
</span><span id="line-832"></span><span>
</span><span id="line-833"></span><span class="hs-comment">-- |Write the supplied value into a 'TVar'.</span><span>
</span><span id="line-834"></span><span id="local-6989586621679539976"><span class="annot"><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-type">writeTVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539976"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679539976"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-835"></span><span id="writeTVar"><span class="annot"><span class="annottext">writeTVar :: forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var hs-var">writeTVar</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span id="local-6989586621679539407"><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539407"><span class="hs-identifier hs-var">tvar#</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679539406"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539406"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; STM ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STM a
</span><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-var">STM</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; STM ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539405"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539405"><span class="hs-identifier hs-var">s1#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-836"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a -&gt; a -&gt; State# RealWorld -&gt; State# RealWorld
forall d a. TVar# d a -&gt; a -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#writeTVar%23"><span class="hs-identifier hs-var">writeTVar#</span></a></span><span> </span><span class="annot"><span class="annottext">TVar# RealWorld a
</span><a href="#local-6989586621679539407"><span class="hs-identifier hs-var">tvar#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539406"><span class="hs-identifier hs-var">val</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539405"><span class="hs-identifier hs-var">s1#</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-837"></span><span>         </span><span id="local-6989586621679539404"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539404"><span class="hs-identifier hs-var">s2#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679539404"><span class="hs-identifier hs-var">s2#</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-838"></span><span>
</span><span id="line-839"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-840"></span><span class="hs-comment">-- MVar utilities</span><span>
</span><span id="line-841"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-842"></span><span>
</span><span id="line-843"></span><span class="hs-comment">-- | Provide an 'IO' action with the current value of an 'MVar'. The 'MVar'</span><span>
</span><span id="line-844"></span><span class="hs-comment">-- will be empty for the duration that the action is running.</span><span>
</span><span id="line-845"></span><span id="local-6989586621679539973"><span id="local-6989586621679539974"><span class="annot"><a href="GHC.Conc.Sync.html#withMVar"><span class="hs-identifier hs-type">withMVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539974"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679539974"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539973"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539973"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-846"></span><span id="withMVar"><span class="annot"><span class="annottext">withMVar :: forall a b. MVar a -&gt; (a -&gt; IO b) -&gt; IO b
</span><a href="GHC.Conc.Sync.html#withMVar"><span class="hs-identifier hs-var hs-var">withMVar</span></a></span></span><span> </span><span id="local-6989586621679539399"><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539399"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679539398"><span class="annot"><span class="annottext">a -&gt; IO b
</span><a href="#local-6989586621679539398"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-847"></span><span>  </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b)
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539396"><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679539396"><span class="hs-identifier hs-var">restore</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-848"></span><span>    </span><span id="local-6989586621679539395"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539395"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar a -&gt; IO a
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539399"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-849"></span><span>    </span><span id="local-6989586621679539393"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539393"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; (forall e. Exception e =&gt; e -&gt; IO b) -&gt; IO b
forall a. IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchAny"><span class="hs-identifier hs-var">catchAny</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO b -&gt; IO b
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679539396"><span class="hs-identifier hs-var">restore</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; IO b
</span><a href="#local-6989586621679539398"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539395"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-850"></span><span>            </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679539388"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539388"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">MVar a -&gt; a -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539399"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539395"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">e -&gt; IO b
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539388"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-851"></span><span>    </span><span class="annot"><span class="annottext">MVar a -&gt; a -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539399"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539395"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-852"></span><span>    </span><span class="annot"><span class="annottext">b -&gt; IO b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679539393"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-853"></span><span>
</span><span id="line-854"></span><span class="hs-comment">-- | Modify the value of an 'MVar'.</span><span>
</span><span id="line-855"></span><span id="local-6989586621679539961"><span class="annot"><a href="GHC.Conc.Sync.html#modifyMVar_"><span class="hs-identifier hs-type">modifyMVar_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539961"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679539961"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539961"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-856"></span><span id="modifyMVar_"><span class="annot"><span class="annottext">modifyMVar_ :: forall a. MVar a -&gt; (a -&gt; IO a) -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#modifyMVar_"><span class="hs-identifier hs-var hs-var">modifyMVar_</span></a></span></span><span> </span><span id="local-6989586621679539381"><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539381"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679539380"><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679539380"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-857"></span><span>  </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO ()) -&gt; IO ()
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO ()) -&gt; IO ())
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539379"><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679539379"><span class="hs-identifier hs-var">restore</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-858"></span><span>    </span><span id="local-6989586621679539378"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539378"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar a -&gt; IO a
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539381"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-859"></span><span>    </span><span id="local-6989586621679539377"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539377"><span class="hs-identifier hs-var">a'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
forall a. IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchAny"><span class="hs-identifier hs-var">catchAny</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679539379"><span class="hs-identifier hs-var">restore</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679539380"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539378"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-860"></span><span>            </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679539373"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539373"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">MVar a -&gt; a -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539381"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539378"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">e -&gt; IO a
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539373"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-861"></span><span>    </span><span class="annot"><span class="annottext">MVar a -&gt; a -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679539381"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539377"><span class="hs-identifier hs-var">a'</span></a></span><span>
</span><span id="line-862"></span><span>    </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-863"></span><span>
</span><span id="line-864"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-865"></span><span class="hs-comment">-- Thread waiting</span><span>
</span><span id="line-866"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-867"></span><span>
</span><span id="line-868"></span><span class="hs-comment">-- Machinery needed to ensure that we only have one copy of certain</span><span>
</span><span id="line-869"></span><span class="hs-comment">-- CAFs in this module even when the base package is present twice, as</span><span>
</span><span id="line-870"></span><span class="hs-comment">-- it is when base is dynamically loaded into GHCi.  The RTS keeps</span><span>
</span><span id="line-871"></span><span class="hs-comment">-- track of the single true value of the CAF, so even when the CAFs in</span><span>
</span><span id="line-872"></span><span class="hs-comment">-- the dynamically-loaded base package are reverted, nothing bad</span><span>
</span><span id="line-873"></span><span class="hs-comment">-- happens.</span><span>
</span><span id="line-874"></span><span class="hs-comment">--</span><span>
</span><span id="line-875"></span><span id="local-6989586621679539958"><span class="annot"><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier hs-type">sharedCAF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679539958"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539958"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539958"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679539958"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-876"></span><span id="sharedCAF"><span class="annot"><span class="annottext">sharedCAF :: forall a. a -&gt; (Ptr a -&gt; IO (Ptr a)) -&gt; IO a
</span><a href="GHC.Conc.Sync.html#sharedCAF"><span class="hs-identifier hs-var hs-var">sharedCAF</span></a></span></span><span> </span><span id="local-6989586621679539366"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539366"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="local-6989586621679539365"><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
</span><a href="#local-6989586621679539365"><span class="hs-identifier hs-var">get_or_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-877"></span><span>   </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span> </span><span class="annot"><span class="annottext">(IO a -&gt; IO a) -&gt; IO a -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-878"></span><span>     </span><span id="local-6989586621679539363"><span class="annot"><span class="annottext">StablePtr a
</span><a href="#local-6989586621679539363"><span class="hs-identifier hs-var">stable_ref</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO (StablePtr a)
forall a. a -&gt; IO (StablePtr a)
</span><a href="GHC.Stable.html#newStablePtr"><span class="hs-identifier hs-var">newStablePtr</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539366"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-879"></span><span>     </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679539362"><span class="annot"><span class="annottext">ref :: Ptr b
</span><a href="#local-6989586621679539362"><span class="hs-identifier hs-var hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; Ptr b
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StablePtr a -&gt; Ptr ()
forall a. StablePtr a -&gt; Ptr ()
</span><a href="GHC.Stable.html#castStablePtrToPtr"><span class="hs-identifier hs-var">castStablePtrToPtr</span></a></span><span> </span><span class="annot"><span class="annottext">StablePtr a
</span><a href="#local-6989586621679539363"><span class="hs-identifier hs-var">stable_ref</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-880"></span><span>     </span><span id="local-6989586621679539359"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679539359"><span class="hs-identifier hs-var">ref2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; IO (Ptr a)
</span><a href="#local-6989586621679539365"><span class="hs-identifier hs-var">get_or_set</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {b}. Ptr b
</span><a href="#local-6989586621679539362"><span class="hs-identifier hs-var">ref</span></a></span><span>
</span><span id="line-881"></span><span>     </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Ptr a
forall {b}. Ptr b
</span><a href="#local-6989586621679539362"><span class="hs-identifier hs-var">ref</span></a></span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679539359"><span class="hs-identifier hs-var">ref2</span></a></span><span>
</span><span id="line-882"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679539366"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-883"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">StablePtr a -&gt; IO ()
forall a. StablePtr a -&gt; IO ()
</span><a href="GHC.Stable.html#freeStablePtr"><span class="hs-identifier hs-var">freeStablePtr</span></a></span><span> </span><span class="annot"><span class="annottext">StablePtr a
</span><a href="#local-6989586621679539363"><span class="hs-identifier hs-var">stable_ref</span></a></span><span>
</span><span id="line-884"></span><span>                </span><span class="annot"><span class="annottext">StablePtr a -&gt; IO a
forall a. StablePtr a -&gt; IO a
</span><a href="GHC.Stable.html#deRefStablePtr"><span class="hs-identifier hs-var">deRefStablePtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr () -&gt; StablePtr a
forall a. Ptr () -&gt; StablePtr a
</span><a href="GHC.Stable.html#castPtrToStablePtr"><span class="hs-identifier hs-var">castPtrToStablePtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr ()
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679539359"><span class="hs-identifier hs-var">ref2</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-885"></span><span>
</span><span id="line-886"></span><span class="annot"><a href="GHC.Conc.Sync.html#reportStackOverflow"><span class="hs-identifier hs-type">reportStackOverflow</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-887"></span><span id="reportStackOverflow"><span class="annot"><span class="annottext">reportStackOverflow :: IO ()
</span><a href="GHC.Conc.Sync.html#reportStackOverflow"><span class="hs-identifier hs-var hs-var">reportStackOverflow</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-888"></span><span>     </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span> </span><span id="local-6989586621679539355"><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539355"><span class="hs-identifier hs-var">tid</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO ThreadId
</span><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-var">myThreadId</span></a></span><span>
</span><span id="line-889"></span><span>     </span><span class="annot"><span class="annottext">ThreadId# -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#c_reportStackOverflow"><span class="hs-identifier hs-var">c_reportStackOverflow</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId#
</span><a href="#local-6989586621679539355"><span class="hs-identifier hs-var">tid</span></a></span><span>
</span><span id="line-890"></span><span>
</span><span id="line-891"></span><span class="annot"><a href="GHC.Conc.Sync.html#reportError"><span class="hs-identifier hs-type">reportError</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-892"></span><span id="reportError"><span class="annot"><span class="annottext">reportError :: SomeException -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#reportError"><span class="hs-identifier hs-var hs-var">reportError</span></a></span></span><span> </span><span id="local-6989586621679539353"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539353"><span class="hs-identifier hs-var">ex</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-893"></span><span>   </span><span id="local-6989586621679539352"><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="#local-6989586621679539352"><span class="hs-identifier hs-var">handler</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (SomeException -&gt; IO ())
</span><a href="GHC.Conc.Sync.html#getUncaughtExceptionHandler"><span class="hs-identifier hs-var">getUncaughtExceptionHandler</span></a></span><span>
</span><span id="line-894"></span><span>   </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="#local-6989586621679539352"><span class="hs-identifier hs-var">handler</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539353"><span class="hs-identifier hs-var">ex</span></a></span><span>
</span><span id="line-895"></span><span>
</span><span id="line-896"></span><span class="hs-comment">-- SUP: Are the hooks allowed to re-enter Haskell land?  If so, remove</span><span>
</span><span id="line-897"></span><span class="hs-comment">-- the unsafe below.</span><span>
</span><span id="line-898"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;reportStackOverflow&quot;</span></span><span>
</span><span id="line-899"></span><span>        </span><span id="c_reportStackOverflow"><span class="annot"><a href="GHC.Conc.Sync.html#c_reportStackOverflow"><span class="hs-identifier hs-var">c_reportStackOverflow</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#ThreadId%23"><span class="hs-identifier hs-type">ThreadId#</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-900"></span><span>
</span><span id="line-901"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;reportHeapOverflow&quot;</span></span><span>
</span><span id="line-902"></span><span>        </span><span id="reportHeapOverflow"><span class="annot"><a href="GHC.Conc.Sync.html#reportHeapOverflow"><span class="hs-identifier hs-var">reportHeapOverflow</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-903"></span><span>
</span><span id="line-904"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#uncaughtExceptionHandler"><span class="hs-pragma hs-type">uncaughtExceptionHandler</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-905"></span><span class="annot"><a href="GHC.Conc.Sync.html#uncaughtExceptionHandler"><span class="hs-identifier hs-type">uncaughtExceptionHandler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-906"></span><span id="uncaughtExceptionHandler"><span class="annot"><span class="annottext">uncaughtExceptionHandler :: IORef (SomeException -&gt; IO ())
</span><a href="GHC.Conc.Sync.html#uncaughtExceptionHandler"><span class="hs-identifier hs-var hs-var">uncaughtExceptionHandler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (IORef (SomeException -&gt; IO ()))
-&gt; IORef (SomeException -&gt; IO ())
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(SomeException -&gt; IO ()) -&gt; IO (IORef (SomeException -&gt; IO ()))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
</span><a href="#local-6989586621679539349"><span class="hs-identifier hs-var">defaultHandler</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-907"></span><span>   </span><span class="hs-keyword">where</span><span>
</span><span id="line-908"></span><span>      </span><span class="annot"><a href="#local-6989586621679539349"><span class="hs-identifier hs-type">defaultHandler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-909"></span><span>      </span><span id="local-6989586621679539349"><span class="annot"><span class="annottext">defaultHandler :: SomeException -&gt; IO ()
</span><a href="#local-6989586621679539349"><span class="hs-identifier hs-var hs-var">defaultHandler</span></a></span></span><span> </span><span id="local-6989586621679539348"><span class="annot"><span class="annottext">se :: SomeException
</span><a href="#local-6989586621679539348"><span class="hs-identifier hs-var">se</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span id="local-6989586621679539342"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539342"><span class="hs-identifier hs-var">ex</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-910"></span><span>         </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; IO ()
</span><a href="GHC.IO.Handle.html#hFlush"><span class="hs-identifier hs-var">hFlush</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier hs-var">stdout</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; (forall e. Exception e =&gt; e -&gt; IO ()) -&gt; IO ()
forall a. IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchAny"><span class="hs-operator hs-var">`catchAny`</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span> </span><span class="annot"><span class="annottext">e
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-911"></span><span>         </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679539335"><span class="annot"><span class="annottext">msg :: String
</span><a href="#local-6989586621679539335"><span class="hs-identifier hs-var hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">e -&gt; Maybe Deadlock
forall a b. (Typeable a, Typeable b) =&gt; a -&gt; Maybe b
</span><a href="Data.Typeable.html#cast"><span class="hs-identifier hs-var">cast</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679539342"><span class="hs-identifier hs-var">ex</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-912"></span><span>               </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Deadlock
</span><a href="GHC.IO.Exception.html#Deadlock"><span class="hs-identifier hs-var">Deadlock</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;no threads to run:  infinite loop or deadlock?&quot;</span></span><span>
</span><span id="line-913"></span><span>               </span><span class="annot"><span class="annottext">Maybe Deadlock
</span><span class="hs-identifier">_</span></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; SomeException -&gt; ShowS
forall a. Show a =&gt; Int -&gt; a -&gt; ShowS
</span><a href="GHC.Show.html#showsPrec"><span class="hs-identifier hs-var">showsPrec</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679539348"><span class="hs-identifier hs-var">se</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-914"></span><span>         </span><span class="annot"><span class="annottext">String -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCString"><span class="hs-identifier hs-var">withCString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;%s&quot;</span></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO ()) -&gt; IO ()) -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539331"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679539331"><span class="hs-identifier hs-var">cfmt</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-915"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (CString -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCString"><span class="hs-identifier hs-var">withCString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679539335"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO ()) -&gt; IO ()) -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679539330"><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679539330"><span class="hs-identifier hs-var">cmsg</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-916"></span><span>            </span><span class="annot"><span class="annottext">CString -&gt; CString -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#errorBelch"><span class="hs-identifier hs-var">errorBelch</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679539331"><span class="hs-identifier hs-var">cfmt</span></a></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679539330"><span class="hs-identifier hs-var">cmsg</span></a></span><span>
</span><span id="line-917"></span><span>
</span><span id="line-918"></span><span class="hs-comment">-- don't use errorBelch() directly, because we cannot call varargs functions</span><span>
</span><span id="line-919"></span><span class="hs-comment">-- using the FFI.</span><span>
</span><span id="line-920"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;HsBase.h errorBelch2&quot;</span></span><span>
</span><span id="line-921"></span><span>   </span><span id="errorBelch"><span class="annot"><a href="GHC.Conc.Sync.html#errorBelch"><span class="hs-identifier hs-var">errorBelch</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-922"></span><span>
</span><span id="line-923"></span><span class="annot"><a href="GHC.Conc.Sync.html#setUncaughtExceptionHandler"><span class="hs-identifier hs-type">setUncaughtExceptionHandler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-924"></span><span id="setUncaughtExceptionHandler"><span class="annot"><span class="annottext">setUncaughtExceptionHandler :: (SomeException -&gt; IO ()) -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#setUncaughtExceptionHandler"><span class="hs-identifier hs-var hs-var">setUncaughtExceptionHandler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (SomeException -&gt; IO ()) -&gt; (SomeException -&gt; IO ()) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (SomeException -&gt; IO ())
</span><a href="GHC.Conc.Sync.html#uncaughtExceptionHandler"><span class="hs-identifier hs-var">uncaughtExceptionHandler</span></a></span><span>
</span><span id="line-925"></span><span>
</span><span id="line-926"></span><span class="annot"><a href="GHC.Conc.Sync.html#getUncaughtExceptionHandler"><span class="hs-identifier hs-type">getUncaughtExceptionHandler</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-927"></span><span id="getUncaughtExceptionHandler"><span class="annot"><span class="annottext">getUncaughtExceptionHandler :: IO (SomeException -&gt; IO ())
</span><a href="GHC.Conc.Sync.html#getUncaughtExceptionHandler"><span class="hs-identifier hs-var hs-var">getUncaughtExceptionHandler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (SomeException -&gt; IO ()) -&gt; IO (SomeException -&gt; IO ())
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (SomeException -&gt; IO ())
</span><a href="GHC.Conc.Sync.html#uncaughtExceptionHandler"><span class="hs-identifier hs-var">uncaughtExceptionHandler</span></a></span><span>
</span><span id="line-928"></span></pre></body></html>